Changeset 105945 in vbox for trunk/src/libs/openssl-3.1.7/crypto/sm2/sm2_crypt.c
- Timestamp:
- Sep 4, 2024 11:32:47 AM (8 months ago)
- svn:sync-xref-src-repo-rev:
- 164679
- Location:
- trunk/src/libs/openssl-3.1.7
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/openssl-3.1.7
- Property svn:mergeinfo
-
old new 25 25 /vendor/openssl/3.0.3:151497-151729 26 26 /vendor/openssl/3.0.7:154371 27 /vendor/openssl/3.1.7:164675-164677
-
- Property svn:mergeinfo
-
trunk/src/libs/openssl-3.1.7/crypto/sm2/sm2_crypt.c
r104078 r105945 1 1 /* 2 * Copyright 2017-202 1The OpenSSL Project Authors. All Rights Reserved.2 * Copyright 2017-2024 The OpenSSL Project Authors. All Rights Reserved. 3 3 * Copyright 2017 Ribose Inc. All Rights Reserved. 4 4 * Ported from Ribose contributions from Botan. … … 66 66 67 67 return field_size; 68 } 69 70 static int is_all_zeros(const unsigned char *msg, size_t msglen) 71 { 72 unsigned char re = 0; 73 size_t i; 74 75 for (i = 0; i < msglen; i++) { 76 re |= msg[i]; 77 } 78 79 return re == 0 ? 1 : 0; 68 80 } 69 81 … … 180 192 memset(ciphertext_buf, 0, *ciphertext_len); 181 193 194 msg_mask = OPENSSL_zalloc(msg_len); 195 if (msg_mask == NULL) { 196 ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE); 197 goto done; 198 } 199 200 again: 182 201 if (!BN_priv_rand_range_ex(k, order, 0, ctx)) { 183 202 ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR); … … 199 218 } 200 219 201 msg_mask = OPENSSL_zalloc(msg_len);202 if (msg_mask == NULL) {203 ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);204 goto done;205 }206 207 220 /* X9.63 with no salt happens to match the KDF used in SM2 */ 208 221 if (!ossl_ecdh_kdf_X9_63(msg_mask, msg_len, x2y2, 2 * field_size, NULL, 0, … … 210 223 ERR_raise(ERR_LIB_SM2, ERR_R_EVP_LIB); 211 224 goto done; 225 } 226 227 if (is_all_zeros(msg_mask, msg_len)) { 228 memset(x2y2, 0, 2 * field_size); 229 goto again; 212 230 } 213 231 … … 365 383 } 366 384 385 if (is_all_zeros(msg_mask, msg_len)) { 386 ERR_raise(ERR_LIB_SM2, SM2_R_INVALID_ENCODING); 387 goto done; 388 } 389 367 390 for (i = 0; i != msg_len; ++i) 368 391 ptext_buf[i] = C2[i] ^ msg_mask[i];
Note:
See TracChangeset
for help on using the changeset viewer.