]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - crypto/sm2/sm2_crypt.c
Convert all {NAME}err() in crypto/ to their corresponding ERR_raise() call
[thirdparty/openssl.git] / crypto / sm2 / sm2_crypt.c
index 6db87f6845d74be41453db4cd28f74d4721560ca..9201d712c14dd5ab09afc0ab064d58e5e3e63293 100644 (file)
@@ -75,17 +75,17 @@ int sm2_plaintext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
     size_t overhead;
 
     if (md_size < 0) {
-        SM2err(SM2_F_SM2_PLAINTEXT_SIZE, SM2_R_INVALID_DIGEST);
+        ERR_raise(ERR_LIB_SM2, SM2_R_INVALID_DIGEST);
         return 0;
     }
     if (field_size == 0) {
-        SM2err(SM2_F_SM2_PLAINTEXT_SIZE, SM2_R_INVALID_FIELD);
+        ERR_raise(ERR_LIB_SM2, 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);
+        ERR_raise(ERR_LIB_SM2, SM2_R_INVALID_ENCODING);
         return 0;
     }
 
@@ -147,13 +147,13 @@ int sm2_encrypt(const EC_KEY *key,
     ctext_struct.C3 = NULL;
 
     if (hash == NULL || C3_size <= 0) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
+        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
         goto done;
     }
 
     field_size = ec_field_size(group);
     if (field_size == 0) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
+        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
         goto done;
     }
 
@@ -161,7 +161,7 @@ int sm2_encrypt(const EC_KEY *key,
     kP = EC_POINT_new(group);
     ctx = BN_CTX_new_ex(libctx);
     if (kG == NULL || kP == NULL || ctx == NULL) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_MALLOC_FAILURE);
+        ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);
         goto done;
     }
 
@@ -173,7 +173,7 @@ int sm2_encrypt(const EC_KEY *key,
     y2 = BN_CTX_get(ctx);
 
     if (y2 == NULL) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_BN_LIB);
+        ERR_raise(ERR_LIB_SM2, ERR_R_BN_LIB);
         goto done;
     }
 
@@ -181,14 +181,14 @@ int sm2_encrypt(const EC_KEY *key,
     C3 = OPENSSL_zalloc(C3_size);
 
     if (x2y2 == NULL || C3 == NULL) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_MALLOC_FAILURE);
+        ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);
         goto done;
     }
 
     memset(ciphertext_buf, 0, *ciphertext_len);
 
     if (!BN_priv_rand_range(k, order)) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
+        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
         goto done;
     }
 
@@ -196,26 +196,26 @@ int sm2_encrypt(const EC_KEY *key,
             || !EC_POINT_get_affine_coordinates(group, kG, x1, y1, ctx)
             || !EC_POINT_mul(group, kP, NULL, P, k, ctx)
             || !EC_POINT_get_affine_coordinates(group, kP, x2, y2, ctx)) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_EC_LIB);
+        ERR_raise(ERR_LIB_SM2, ERR_R_EC_LIB);
         goto done;
     }
 
     if (BN_bn2binpad(x2, x2y2, field_size) < 0
             || BN_bn2binpad(y2, x2y2 + field_size, field_size) < 0) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
+        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
         goto done;
     }
 
     msg_mask = OPENSSL_zalloc(msg_len);
     if (msg_mask == NULL) {
-       SM2err(SM2_F_SM2_ENCRYPT, ERR_R_MALLOC_FAILURE);
+       ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);
        goto done;
    }
 
     /* X9.63 with no salt happens to match the KDF used in SM2 */
     if (!ecdh_KDF_X9_63(msg_mask, msg_len, x2y2, 2 * field_size, NULL, 0,
                         digest, libctx, propq)) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_EVP_LIB);
+        ERR_raise(ERR_LIB_SM2, ERR_R_EVP_LIB);
         goto done;
     }
 
@@ -224,7 +224,7 @@ int sm2_encrypt(const EC_KEY *key,
 
     fetched_digest = EVP_MD_fetch(libctx, EVP_MD_name(digest), propq);
     if (fetched_digest == NULL) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
+        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
         goto done;
     }
     if (EVP_DigestInit(hash, fetched_digest) == 0
@@ -232,7 +232,7 @@ int sm2_encrypt(const EC_KEY *key,
             || EVP_DigestUpdate(hash, msg, msg_len) == 0
             || EVP_DigestUpdate(hash, x2y2 + field_size, field_size) == 0
             || EVP_DigestFinal(hash, C3, NULL) == 0) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_EVP_LIB);
+        ERR_raise(ERR_LIB_SM2, ERR_R_EVP_LIB);
         goto done;
     }
 
@@ -242,19 +242,19 @@ int sm2_encrypt(const EC_KEY *key,
     ctext_struct.C2 = ASN1_OCTET_STRING_new();
 
     if (ctext_struct.C3 == NULL || ctext_struct.C2 == NULL) {
-       SM2err(SM2_F_SM2_ENCRYPT, ERR_R_MALLOC_FAILURE);
+       ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);
        goto done;
     }
     if (!ASN1_OCTET_STRING_set(ctext_struct.C3, C3, C3_size)
             || !ASN1_OCTET_STRING_set(ctext_struct.C2, msg_mask, msg_len)) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
+        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
         goto done;
     }
 
     ciphertext_leni = i2d_SM2_Ciphertext(&ctext_struct, &ciphertext_buf);
     /* Ensure cast to size_t is safe */
     if (ciphertext_leni < 0) {
-        SM2err(SM2_F_SM2_ENCRYPT, ERR_R_INTERNAL_ERROR);
+        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
         goto done;
     }
     *ciphertext_len = (size_t)ciphertext_leni;
@@ -308,12 +308,12 @@ int sm2_decrypt(const EC_KEY *key,
     sm2_ctext = d2i_SM2_Ciphertext(NULL, &ciphertext, ciphertext_len);
 
     if (sm2_ctext == NULL) {
-        SM2err(SM2_F_SM2_DECRYPT, SM2_R_ASN1_ERROR);
+        ERR_raise(ERR_LIB_SM2, SM2_R_ASN1_ERROR);
         goto done;
     }
 
     if (sm2_ctext->C3->length != hash_size) {
-        SM2err(SM2_F_SM2_DECRYPT, SM2_R_INVALID_ENCODING);
+        ERR_raise(ERR_LIB_SM2, SM2_R_INVALID_ENCODING);
         goto done;
     }
 
@@ -323,7 +323,7 @@ int sm2_decrypt(const EC_KEY *key,
 
     ctx = BN_CTX_new_ex(libctx);
     if (ctx == NULL) {
-        SM2err(SM2_F_SM2_DECRYPT, ERR_R_MALLOC_FAILURE);
+        ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);
         goto done;
     }
 
@@ -332,7 +332,7 @@ int sm2_decrypt(const EC_KEY *key,
     y2 = BN_CTX_get(ctx);
 
     if (y2 == NULL) {
-        SM2err(SM2_F_SM2_DECRYPT, ERR_R_BN_LIB);
+        ERR_raise(ERR_LIB_SM2, ERR_R_BN_LIB);
         goto done;
     }
 
@@ -341,13 +341,13 @@ int sm2_decrypt(const EC_KEY *key,
     computed_C3 = OPENSSL_zalloc(hash_size);
 
     if (msg_mask == NULL || x2y2 == NULL || computed_C3 == NULL) {
-        SM2err(SM2_F_SM2_DECRYPT, ERR_R_MALLOC_FAILURE);
+        ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);
         goto done;
     }
 
     C1 = EC_POINT_new(group);
     if (C1 == NULL) {
-        SM2err(SM2_F_SM2_DECRYPT, ERR_R_MALLOC_FAILURE);
+        ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);
         goto done;
     }
 
@@ -356,7 +356,7 @@ int sm2_decrypt(const EC_KEY *key,
             || !EC_POINT_mul(group, C1, NULL, C1, EC_KEY_get0_private_key(key),
                              ctx)
             || !EC_POINT_get_affine_coordinates(group, C1, x2, y2, ctx)) {
-        SM2err(SM2_F_SM2_DECRYPT, ERR_R_EC_LIB);
+        ERR_raise(ERR_LIB_SM2, ERR_R_EC_LIB);
         goto done;
     }
 
@@ -364,7 +364,7 @@ int sm2_decrypt(const EC_KEY *key,
             || BN_bn2binpad(y2, x2y2 + field_size, field_size) < 0
             || !ecdh_KDF_X9_63(msg_mask, msg_len, x2y2, 2 * field_size, NULL, 0,
                                digest, libctx, propq)) {
-        SM2err(SM2_F_SM2_DECRYPT, ERR_R_INTERNAL_ERROR);
+        ERR_raise(ERR_LIB_SM2, ERR_R_INTERNAL_ERROR);
         goto done;
     }
 
@@ -373,7 +373,7 @@ int sm2_decrypt(const EC_KEY *key,
 
     hash = EVP_MD_CTX_new();
     if (hash == NULL) {
-        SM2err(SM2_F_SM2_DECRYPT, ERR_R_MALLOC_FAILURE);
+        ERR_raise(ERR_LIB_SM2, ERR_R_MALLOC_FAILURE);
         goto done;
     }
 
@@ -382,12 +382,12 @@ int sm2_decrypt(const EC_KEY *key,
             || !EVP_DigestUpdate(hash, ptext_buf, msg_len)
             || !EVP_DigestUpdate(hash, x2y2 + field_size, field_size)
             || !EVP_DigestFinal(hash, computed_C3, NULL)) {
-        SM2err(SM2_F_SM2_DECRYPT, ERR_R_EVP_LIB);
+        ERR_raise(ERR_LIB_SM2, ERR_R_EVP_LIB);
         goto done;
     }
 
     if (CRYPTO_memcmp(computed_C3, C3, hash_size) != 0) {
-        SM2err(SM2_F_SM2_DECRYPT, SM2_R_INVALID_DIGEST);
+        ERR_raise(ERR_LIB_SM2, SM2_R_INVALID_DIGEST);
         goto done;
     }