VirtualBox

Ignore:
Timestamp:
Sep 4, 2024 11:32:47 AM (8 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
164679
Message:

openssl-3.1.7: Applied and adjusted our OpenSSL changes to 3.1.7. bugref:10757

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  
        2525/vendor/openssl/3.0.3:151497-151729
        2626/vendor/openssl/3.0.7:154371
         27/vendor/openssl/3.1.7:164675-164677
  • trunk/src/libs/openssl-3.1.7/crypto/sm2/sm2_crypt.c

    r104078 r105945  
    11/*
    2  * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
     2 * Copyright 2017-2024 The OpenSSL Project Authors. All Rights Reserved.
    33 * Copyright 2017 Ribose Inc. All Rights Reserved.
    44 * Ported from Ribose contributions from Botan.
     
    6666
    6767    return field_size;
     68}
     69
     70static 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;
    6880}
    6981
     
    180192    memset(ciphertext_buf, 0, *ciphertext_len);
    181193
     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
     200again:
    182201    if (!BN_priv_rand_range_ex(k, order, 0, ctx)) {
    183202        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
     
    199218    }
    200219
    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 
    207220    /* X9.63 with no salt happens to match the KDF used in SM2 */
    208221    if (!ossl_ecdh_kdf_X9_63(msg_mask, msg_len, x2y2, 2 * field_size, NULL, 0,
     
    210223        ERR_raise(ERR_LIB_SM2, ERR_R_EVP_LIB);
    211224        goto done;
     225    }
     226
     227    if (is_all_zeros(msg_mask, msg_len)) {
     228        memset(x2y2, 0, 2 * field_size);
     229        goto again;
    212230    }
    213231
     
    365383    }
    366384
     385    if (is_all_zeros(msg_mask, msg_len)) {
     386        ERR_raise(ERR_LIB_SM2, SM2_R_INVALID_ENCODING);
     387        goto done;
     388    }
     389
    367390    for (i = 0; i != msg_len; ++i)
    368391        ptext_buf[i] = C2[i] ^ msg_mask[i];
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette