mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-20 21:49:28 +00:00
37 lines
1.1 KiB
C
37 lines
1.1 KiB
C
/* Provenance: openssl/openssl sm2_plaintext_size (vuln).
|
|||
|
|
* repo: openssl/openssl
|
||
|
|
* commit: 8c74c9d1ade0fbdab5b815ddb747351b8b839641
|
||
|
|
* parent: 8c74c9d1ade0fbdab5b815ddb747351b8b839641
|
||
|
|
* commit_url: https://github.com/openssl/openssl/commit/59f5e75f3bced8fc0e130d72a3f582cf7b480b46
|
||
|
|
* cve: CVE-2021-3711
|
||
|
|
* license: OpenSSL License
|
||
|
|
* function: sm2_plaintext_size
|
||
|
|
* relpath: crypto/sm2/sm2_crypt.c
|
||
|
|
*/
|
||
|
|
|
||
|
|
int sm2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
|
||
|
|
size_t *pt_size)
|
||
|
|
{
|
||
|
|
const size_t field_size = ec_field_size(EC_KEY_get0_group(key));
|
||
|
|
const int md_size = EVP_MD_size(digest);
|
||
|
|
size_t overhead;
|
||
|
|
|
||
|
|
if (md_size < 0) {
|
||
|
|
SM2err(SM2_F_SM2_PLAINTEXT_SIZE, SM2_R_INVALID_DIGEST);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (field_size == 0) {
|
||
|
|
SM2err(SM2_F_SM2_PLAINTEXT_SIZE, SM2_R_INVALID_FIELD);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
overhead = 10 + 2 * field_size + (size_t)md_size;
|
||
|
|
if (msg_len <= overhead) {
|
||
|
|
SM2err(SM2_F_SM2_PLAINTEXT_SIZE, SM2_R_INVALID_ENCODING);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
*pt_size = msg_len - overhead;
|
||
|
|
return 1;
|
||
|
|
}
|