mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-18 14:26:17 +08:00
Add accurate asn.1 siganture/ciphertext size
This commit is contained in:
@@ -67,8 +67,50 @@ ASN1_SEQUENCE(SM2CiphertextValue) = {
|
||||
IMPLEMENT_ASN1_FUNCTIONS(SM2CiphertextValue)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(SM2CiphertextValue)
|
||||
|
||||
int SM2CiphertextValue_size(const EC_GROUP *group, int inlen)
|
||||
int SM2CiphertextValue_size(const EC_GROUP *group, size_t inlen)
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
int ret;
|
||||
ASN1_OCTET_STRING s;
|
||||
int len = 0, i;
|
||||
|
||||
if (inlen > SM2_MAX_PLAINTEXT_LENGTH) {
|
||||
SM2err(SM2_F_SM2CIPHERTEXTVALUE_SIZE, SM2_R_PLAINTEXT_TOO_LONG);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (group) {
|
||||
ASN1_INTEGER a;
|
||||
unsigned char buf[4] = {0xff};
|
||||
|
||||
/* ASN1_INTEGER xCoordinate, yCoordinate */
|
||||
if (!(i = EC_GROUP_order_bits(group))) {
|
||||
SM2err(SM2_F_SM2CIPHERTEXTVALUE_SIZE, ERR_R_EC_LIB);
|
||||
return 0;
|
||||
}
|
||||
a.length = (i + 7)/8;
|
||||
a.data = buf;
|
||||
a.type = V_ASN1_INTEGER;
|
||||
i = i2d_ASN1_INTEGER(&a, NULL);
|
||||
len = i + i;
|
||||
|
||||
/* ASN1_OCTET_STRING hash 32 */
|
||||
s.length = SM3_DIGEST_LENGTH;
|
||||
s.data = NULL;
|
||||
s.type = V_ASN1_OCTET_STRING;
|
||||
i = i2d_ASN1_OCTET_STRING(&s, NULL);
|
||||
len += i;
|
||||
|
||||
} else {
|
||||
len += 104;
|
||||
}
|
||||
|
||||
/* ASN1_OCTET_STRING ciphertext inlen */
|
||||
s.length = inlen;
|
||||
s.data = NULL;
|
||||
s.type = V_ASN1_OCTET_STRING;
|
||||
i = i2d_ASN1_OCTET_STRING(&s, NULL);
|
||||
len += i;
|
||||
|
||||
ret = ASN1_object_size(1, len, V_ASN1_SEQUENCE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -21,6 +21,7 @@
|
||||
static ERR_STRING_DATA SM2_str_functs[] = {
|
||||
{ERR_FUNC(SM2_F_I2O_SM2CIPHERTEXTVALUE), "i2o_SM2CiphertextValue"},
|
||||
{ERR_FUNC(SM2_F_O2I_SM2CIPHERTEXTVALUE), "o2i_SM2CiphertextValue"},
|
||||
{ERR_FUNC(SM2_F_SM2CIPHERTEXTVALUE_SIZE), "SM2CiphertextValue_size"},
|
||||
{ERR_FUNC(SM2_F_SM2_DECRYPT), "SM2_decrypt"},
|
||||
{ERR_FUNC(SM2_F_SM2_DO_DECRYPT), "SM2_do_decrypt"},
|
||||
{ERR_FUNC(SM2_F_SM2_DO_ENCRYPT), "SM2_do_encrypt"},
|
||||
@@ -45,6 +46,7 @@ static ERR_STRING_DATA SM2_str_reasons[] = {
|
||||
{ERR_REASON(SM2_R_KDF_FAILURE), "kdf failure"},
|
||||
{ERR_REASON(SM2_R_MISSING_PARAMETERS), "missing parameters"},
|
||||
{ERR_REASON(SM2_R_NEED_NEW_SETUP_VALUES), "need new setup values"},
|
||||
{ERR_REASON(SM2_R_PLAINTEXT_TOO_LONG), "plaintext too long"},
|
||||
{ERR_REASON(SM2_R_RANDOM_NUMBER_GENERATION_FAILED),
|
||||
"random number generation failed"},
|
||||
{0, NULL}
|
||||
|
||||
Reference in New Issue
Block a user