diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2022-06-28 07:53:59 +0200 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2022-07-19 08:44:19 +0200 |
commit | 7c310e872e72977432b3520c5d27641e13815548 (patch) | |
tree | 6a280ea938354730e9421c1b375ab689f9fa3224 /crypto/asn1 | |
parent | libcrypto refactoring: make more use of ASN1_STRING_set0() (diff) | |
download | openssl-7c310e872e72977432b3520c5d27641e13815548.tar.xz openssl-7c310e872e72977432b3520c5d27641e13815548.zip |
libcrypto refactoring: introduce and use ossl_asn1_string_set_bits_left()
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/18668)
Diffstat (limited to 'crypto/asn1')
-rw-r--r-- | crypto/asn1/a_bitstr.c | 3 | ||||
-rw-r--r-- | crypto/asn1/a_sign.c | 6 | ||||
-rw-r--r-- | crypto/asn1/asn1_gen.c | 7 | ||||
-rw-r--r-- | crypto/asn1/asn1_lib.c | 6 | ||||
-rw-r--r-- | crypto/asn1/asn1_local.h | 2 |
5 files changed, 13 insertions, 11 deletions
diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c index f8938ad107..7b3991a071 100644 --- a/crypto/asn1/a_bitstr.c +++ b/crypto/asn1/a_bitstr.c @@ -110,8 +110,7 @@ ASN1_BIT_STRING *ossl_c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, * We do this to preserve the settings. If we modify the settings, via * the _set_bit function, we will recalculate on output */ - ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */ - ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */ + ossl_asn1_string_set_bits_left(ret, i); if (len-- > 1) { /* using one because of the bits left byte */ s = OPENSSL_malloc((int)len); diff --git a/crypto/asn1/a_sign.c b/crypto/asn1/a_sign.c index fc3f15007e..a1e2719e64 100644 --- a/crypto/asn1/a_sign.c +++ b/crypto/asn1/a_sign.c @@ -102,8 +102,7 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2, * In the interests of compatibility, I'll make sure that the bit string * has a 'not-used bits' value of 0 */ - signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); - signature->flags |= ASN1_STRING_FLAG_BITS_LEFT; + ossl_asn1_string_set_bits_left(signature, 0); err: EVP_MD_CTX_free(ctx); OPENSSL_clear_free((char *)buf_in, inll); @@ -286,8 +285,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, * In the interests of compatibility, I'll make sure that the bit string * has a 'not-used bits' value of 0 */ - signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); - signature->flags |= ASN1_STRING_FLAG_BITS_LEFT; + ossl_asn1_string_set_bits_left(signature, 0); err: OPENSSL_clear_free((char *)buf_in, inl); OPENSSL_clear_free((char *)buf_out, outll); diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c index 5b5a469fa9..c590c62fc2 100644 --- a/crypto/asn1/asn1_gen.c +++ b/crypto/asn1/asn1_gen.c @@ -714,11 +714,8 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) goto bad_form; } - if ((utype == V_ASN1_BIT_STRING) && no_unused) { - atmp->value.asn1_string->flags - &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); - atmp->value.asn1_string->flags |= ASN1_STRING_FLAG_BITS_LEFT; - } + if ((utype == V_ASN1_BIT_STRING) && no_unused) + ossl_asn1_string_set_bits_left(atmp->value.asn1_string, 0); break; diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index 5359cbc117..55e3ddbafd 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -248,6 +248,12 @@ int ASN1_object_size(int constructed, int length, int tag) return ret + length; } +void ossl_asn1_string_set_bits_left(ASN1_STRING *str, unsigned int num) +{ + str->flags &= ~0x07; + str->flags |= ASN1_STRING_FLAG_BITS_LEFT | (num & 0x07); +} + int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) { if (str == NULL) diff --git a/crypto/asn1/asn1_local.h b/crypto/asn1/asn1_local.h index f73bd8fc6a..10e9fcb7de 100644 --- a/crypto/asn1/asn1_local.h +++ b/crypto/asn1/asn1_local.h @@ -9,6 +9,8 @@ /* Internal ASN1 structures and functions: not for application use */ +#include "crypto/asn1.h" + typedef const ASN1_VALUE const_ASN1_VALUE; SKM_DEFINE_STACK_OF(const_ASN1_VALUE, const ASN1_VALUE, ASN1_VALUE) |