* 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);
* 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);
* 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);
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;
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)
/* 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)
if ((prot = ASN1_BIT_STRING_new()) == NULL)
goto end;
/* OpenSSL defaults all bit strings to be encoded as ASN.1 NamedBitList */
- prot->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
- prot->flags |= ASN1_STRING_FLAG_BITS_LEFT;
+ ossl_asn1_string_set_bits_left(prot, 0);
if (!ASN1_BIT_STRING_set(prot, protection, sig_len)) {
ASN1_BIT_STRING_free(prot);
prot = NULL;
#include <openssl/err.h>
#include <openssl/core_names.h>
#include "internal/sizes.h"
+#include "crypto/asn1.h"
#include "crypto/evp.h"
#include "cms_local.h"
if (penclen <= 0)
goto err;
ASN1_STRING_set0(pubkey, penc, penclen);
- pubkey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
- pubkey->flags |= ASN1_STRING_FLAG_BITS_LEFT;
+ ossl_asn1_string_set_bits_left(pubkey, 0);
penc = NULL;
(void)X509_ALGOR_set0(talg, OBJ_nid2obj(NID_dhpublicnumber),
#include <openssl/err.h>
#include <openssl/decoder.h>
#include "internal/sizes.h"
+#include "crypto/asn1.h"
#include "crypto/evp.h"
#include "cms_local.h"
penclen = EVP_PKEY_get1_encoded_public_key(pkey, &penc);
ASN1_STRING_set0(pubkey, penc, penclen);
- pubkey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
- pubkey->flags |= ASN1_STRING_FLAG_BITS_LEFT;
+ ossl_asn1_string_set_bits_left(pubkey, 0);
penc = NULL;
(void)X509_ALGOR_set0(talg, OBJ_nid2obj(NID_X9_62_id_ecPublicKey),
#include <openssl/asn1t.h>
#include <openssl/objects.h>
#include "internal/nelem.h"
+#include "crypto/asn1.h"
#include "crypto/asn1_dsa.h"
#ifndef FIPS_MODULE
ERR_raise(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
goto err;
}
- curve->seed->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
- curve->seed->flags |= ASN1_STRING_FLAG_BITS_LEFT;
+ ossl_asn1_string_set_bits_left(curve->seed, 0);
if (!ASN1_BIT_STRING_set(curve->seed, group->seed,
(int)group->seed_len)) {
ERR_raise(ERR_LIB_EC, ERR_R_ASN1_LIB);
goto err;
}
- priv_key->publicKey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
- priv_key->publicKey->flags |= ASN1_STRING_FLAG_BITS_LEFT;
+ ossl_asn1_string_set_bits_left(priv_key->publicKey, 0);
ASN1_STRING_set0(priv_key->publicKey, pub, publen);
pub = NULL;
}
goto err;
if (!ASN1_BIT_STRING_set(aor->u.addressPrefix, addr, bytelen))
goto err;
- aor->u.addressPrefix->flags &= ~7;
- aor->u.addressPrefix->flags |= ASN1_STRING_FLAG_BITS_LEFT;
if (bitlen > 0) {
aor->u.addressPrefix->data[bytelen - 1] &= ~(0xFF >> bitlen);
- aor->u.addressPrefix->flags |= 8 - bitlen;
}
+ ossl_asn1_string_set_bits_left(aor->u.addressPrefix, 8 - bitlen);
*result = aor;
return 1;
for (i = length; i > 0 && min[i - 1] == 0x00; --i) ;
if (!ASN1_BIT_STRING_set(aor->u.addressRange->min, min, i))
goto err;
- aor->u.addressRange->min->flags &= ~7;
- aor->u.addressRange->min->flags |= ASN1_STRING_FLAG_BITS_LEFT;
+ ossl_asn1_string_set_bits_left(aor->u.addressRange->min, 0);
if (i > 0) {
unsigned char b = min[i - 1];
int j = 1;
for (i = length; i > 0 && max[i - 1] == 0xFF; --i) ;
if (!ASN1_BIT_STRING_set(aor->u.addressRange->max, max, i))
goto err;
- aor->u.addressRange->max->flags &= ~7;
- aor->u.addressRange->max->flags |= ASN1_STRING_FLAG_BITS_LEFT;
+ ossl_asn1_string_set_bits_left(aor->u.addressRange->max, 0);
if (i > 0) {
unsigned char b = max[i - 1];
int j = 1;
unsigned char *penc, int penclen)
{
ASN1_STRING_set0(pub->public_key, penc, penclen);
- /* Set number of unused bits to zero */
- pub->public_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
- pub->public_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
+ ossl_asn1_string_set_bits_left(pub->public_key, 0);
}
int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj,
X509_ALGOR *ossl_X509_ALGOR_from_nid(int nid, int ptype, void *pval);
time_t asn1_string_to_time_t(const char *asn1_string);
+void ossl_asn1_string_set_bits_left(ASN1_STRING *str, unsigned int num);
#endif /* ndef OSSL_CRYPTO_ASN1_H */
# endif
# include "internal/common.h"
+# include "crypto/asn1.h"
# include <openssl/crypto.h>
# include <openssl/buffer.h>
-}
-# define ASN1_STRING_FLAG_BITS_LEFT 0x08/* Set if 0x07 has bits left value */
+# define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
/*
* This indicates that the ASN1_STRING is not a real value but just a place
* holder for the location where indefinite length constructed data should be