Coverage Report

Created: 2026-01-06 16:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/util/sm3.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "util/sm3.h"
19
20
#include <openssl/evp.h>
21
#include <stdint.h>
22
23
#include "common/logging.h"
24
25
namespace doris {
26
27
257
SM3Digest::SM3Digest() {
28
257
    _md = EVP_sm3();
29
257
    _ctx = EVP_MD_CTX_new();
30
257
    EVP_DigestInit_ex(_ctx, _md, NULL);
31
257
}
32
33
257
SM3Digest::~SM3Digest() {
34
257
    EVP_MD_CTX_free(_ctx);
35
257
}
36
37
349
void SM3Digest::update(const void* data, size_t length) {
38
349
    EVP_DigestUpdate(_ctx, data, length);
39
349
}
40
41
257
void SM3Digest::digest() {
42
257
    unsigned char buf[SM3_DIGEST_LENGTH];
43
257
    uint32_t length;
44
257
    EVP_DigestFinal_ex(_ctx, buf, &length);
45
257
    DCHECK_EQ(SM3_DIGEST_LENGTH, length);
46
47
257
    char hex_buf[2 * SM3_DIGEST_LENGTH];
48
49
257
    static char dig_vec_lower[] = "0123456789abcdef";
50
257
    char* to = hex_buf;
51
8.48k
    for (int i = 0; i < SM3_DIGEST_LENGTH; ++i) {
52
8.22k
        *to++ = dig_vec_lower[buf[i] >> 4];
53
8.22k
        *to++ = dig_vec_lower[buf[i] & 0x0F];
54
8.22k
    }
55
257
    _hex.assign(hex_buf, 2 * SM3_DIGEST_LENGTH);
56
257
}
57
58
} // namespace doris