Fix format script.

The format script didn't correctly recognise some ASN.1 macros and
didn't reformat some files as a result. Fix script and reformat
affected files.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit 437b14b533fe7f7408e3ebca6d5569f1d3347b1a)
This commit is contained in:
Dr. Stephen Henson 2015-03-02 13:26:29 +00:00
parent 5c921f14cb
commit 1810b04728
3 changed files with 117 additions and 95 deletions

View File

@ -98,46 +98,55 @@ ASN1_ITEM_end(CBIGNUM)
static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
*pval = (ASN1_VALUE *)BN_new(); *pval = (ASN1_VALUE *)BN_new();
if(*pval) return 1; if (*pval)
else return 0; return 1;
else
return 0;
} }
static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it) static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
if(!*pval) return; if (!*pval)
if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval); return;
else BN_free((BIGNUM *)*pval); if (it->size & BN_SENSITIVE)
*pval = NULL; BN_clear_free((BIGNUM *)*pval);
else
BN_free((BIGNUM *)*pval);
*pval = NULL;
} }
static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
const ASN1_ITEM *it)
{ {
BIGNUM *bn; BIGNUM *bn;
int pad; int pad;
if(!*pval) return -1; if (!*pval)
bn = (BIGNUM *)*pval; return -1;
/* If MSB set in an octet we need a padding byte */ bn = (BIGNUM *)*pval;
if(BN_num_bits(bn) & 0x7) pad = 0; /* If MSB set in an octet we need a padding byte */
else pad = 1; if (BN_num_bits(bn) & 0x7)
if(cont) { pad = 0;
if(pad) *cont++ = 0; else
BN_bn2bin(bn, cont); pad = 1;
} if (cont) {
return pad + BN_num_bytes(bn); if (pad)
*cont++ = 0;
BN_bn2bin(bn, cont);
}
return pad + BN_num_bytes(bn);
} }
static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it) int utype, char *free_cont, const ASN1_ITEM *it)
{ {
BIGNUM *bn; BIGNUM *bn;
if(!*pval) bn_new(pval, it); if (!*pval)
bn = (BIGNUM *)*pval; bn_new(pval, it);
if(!BN_bin2bn(cont, len, bn)) { bn = (BIGNUM *)*pval;
bn_free(pval, it); if (!BN_bin2bn(cont, len, bn)) {
return 0; bn_free(pval, it);
} return 0;
return 1; }
return 1;
} }

View File

@ -97,87 +97,100 @@ ASN1_ITEM_end(ZLONG)
static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
*(long *)pval = it->size; *(long *)pval = it->size;
return 1; return 1;
} }
static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it) static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
*(long *)pval = it->size; *(long *)pval = it->size;
} }
static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
const ASN1_ITEM *it)
{ {
long ltmp; long ltmp;
unsigned long utmp; unsigned long utmp;
int clen, pad, i; int clen, pad, i;
/* this exists to bypass broken gcc optimization */ /* this exists to bypass broken gcc optimization */
char *cp = (char *)pval; char *cp = (char *)pval;
/* use memcpy, because we may not be long aligned */ /* use memcpy, because we may not be long aligned */
memcpy(&ltmp, cp, sizeof(long)); memcpy(&ltmp, cp, sizeof(long));
if(ltmp == it->size) return -1; if (ltmp == it->size)
/* Convert the long to positive: we subtract one if negative so return -1;
* we can cleanly handle the padding if only the MSB of the leading /*
* octet is set. * Convert the long to positive: we subtract one if negative so we can
*/ * cleanly handle the padding if only the MSB of the leading octet is
if(ltmp < 0) utmp = -ltmp - 1; * set.
else utmp = ltmp; */
clen = BN_num_bits_word(utmp); if (ltmp < 0)
/* If MSB of leading octet set we need to pad */ utmp = -ltmp - 1;
if(!(clen & 0x7)) pad = 1; else
else pad = 0; utmp = ltmp;
clen = BN_num_bits_word(utmp);
/* If MSB of leading octet set we need to pad */
if (!(clen & 0x7))
pad = 1;
else
pad = 0;
/* Convert number of bits to number of octets */ /* Convert number of bits to number of octets */
clen = (clen + 7) >> 3; clen = (clen + 7) >> 3;
if(cont) { if (cont) {
if(pad) *cont++ = (ltmp < 0) ? 0xff : 0; if (pad)
for(i = clen - 1; i >= 0; i--) { *cont++ = (ltmp < 0) ? 0xff : 0;
cont[i] = (unsigned char)(utmp & 0xff); for (i = clen - 1; i >= 0; i--) {
if(ltmp < 0) cont[i] ^= 0xff; cont[i] = (unsigned char)(utmp & 0xff);
utmp >>= 8; if (ltmp < 0)
} cont[i] ^= 0xff;
utmp >>= 8;
} }
return clen + pad; }
return clen + pad;
} }
static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
int utype, char *free_cont, const ASN1_ITEM *it) int utype, char *free_cont, const ASN1_ITEM *it)
{ {
int neg, i; int neg, i;
long ltmp; long ltmp;
unsigned long utmp = 0; unsigned long utmp = 0;
char *cp = (char *)pval; char *cp = (char *)pval;
if(len > (int)sizeof(long)) { if (len > (int)sizeof(long)) {
ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
return 0; return 0;
} }
/* Is it negative? */ /* Is it negative? */
if(len && (cont[0] & 0x80)) neg = 1; if (len && (cont[0] & 0x80))
else neg = 0; neg = 1;
utmp = 0; else
for(i = 0; i < len; i++) { neg = 0;
utmp <<= 8; utmp = 0;
if(neg) utmp |= cont[i] ^ 0xff; for (i = 0; i < len; i++) {
else utmp |= cont[i]; utmp <<= 8;
} if (neg)
ltmp = (long)utmp; utmp |= cont[i] ^ 0xff;
if(neg) { else
ltmp++; utmp |= cont[i];
ltmp = -ltmp; }
} ltmp = (long)utmp;
if(ltmp == it->size) { if (neg) {
ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); ltmp++;
return 0; ltmp = -ltmp;
} }
memcpy(cp, &ltmp, sizeof(long)); if (ltmp == it->size) {
return 1; ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
return 0;
}
memcpy(cp, &ltmp, sizeof(long));
return 1;
} }
static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it,
int indent, const ASN1_PCTX *pctx) int indent, const ASN1_PCTX *pctx)
{ {
return BIO_printf(out, "%ld\n", *(long *)pval); return BIO_printf(out, "%ld\n", *(long *)pval);
} }

View File

@ -119,7 +119,7 @@ do
-e 's/^((DECLARE|IMPLEMENT)_(EXTERN_ASN1|ASN1|ADB|STACK_OF|PKCS12_STACK_OF).*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \ -e 's/^((DECLARE|IMPLEMENT)_(EXTERN_ASN1|ASN1|ADB|STACK_OF|PKCS12_STACK_OF).*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
-e 's/^([ \t]*(make_dh|make_dh_bn|make_rfc5114_td)\(.*\)[ \t,]*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \ -e 's/^([ \t]*(make_dh|make_dh_bn|make_rfc5114_td)\(.*\)[ \t,]*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
-e 's/^(ASN1_ADB_TEMPLATE\(.*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \ -e 's/^(ASN1_ADB_TEMPLATE\(.*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
-e 's/^((ASN1|ADB)_.*_END\(.*[\){=,;]+[ \t]*)$/$1\n\/**INDENT-ON**\//;' \ -e 's/^((ASN1|ADB)_.*_(end|END)\(.*[\){=,;]+[ \t]*)$/$1\n\/**INDENT-ON**\//;' \
-e '/ASN1_(ITEM_ref|ITEM_ptr|ITEM_rptr|PCTX)/ || s/^((ASN1|ADB)_[^\*]*[){=,]+[ \t]*)$/\/**INDENT-OFF**\/\n$1/;' \ -e '/ASN1_(ITEM_ref|ITEM_ptr|ITEM_rptr|PCTX)/ || s/^((ASN1|ADB)_[^\*]*[){=,]+[ \t]*)$/\/**INDENT-OFF**\/\n$1/;' \
-e 's/^(} (ASN1|ADB)_[^\*]*[\){=,;]+)$/$1\n\/**INDENT-ON**\//;' \ -e 's/^(} (ASN1|ADB)_[^\*]*[\){=,;]+)$/$1\n\/**INDENT-ON**\//;' \
| \ | \