int
i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
{
- int ret, j,bits, len;
+ int ret, j, bits, len;
unsigned char *p, *d;
if (a == NULL)
if (a == NULL)
return 0;
- a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
+ a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear, set on write */
if ((a->length < (w + 1)) || (a->data == NULL)) {
if (!value)
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include <openssl/buffer.h>
#include <openssl/x509.h>
-int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
- unsigned char *md, unsigned int *len)
+int
+ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
+ unsigned char *md, unsigned int *len)
{
int i;
unsigned char *str = NULL;
- i=ASN1_item_i2d(asn,&str, it);
- if (!str) return(0);
+ i = ASN1_item_i2d(asn, &str, it);
+ if (!str)
+ return (0);
if (!EVP_Digest(str, i, md, len, type, NULL))
return 0;
free(str);
- return(1);
+ return (1);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#ifndef NO_OLD_ASN1
-void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
+void *
+ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
{
- unsigned char *b,*p;
+ unsigned char *b, *p;
const unsigned char *p2;
int i;
char *ret;
if (x == NULL)
- return(NULL);
+ return (NULL);
- i=i2d(x,NULL);
- b=malloc(i+10);
+ i = i2d(x, NULL);
+ b = malloc(i + 10);
if (b == NULL) {
- ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE);
- return(NULL);
+ ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE);
+ return (NULL);
}
- p= b;
- i=i2d(x,&p);
- p2= b;
- ret=d2i(NULL,&p2,i);
+ p = b;
+ i = i2d(x, &p);
+ p2 = b;
+ ret = d2i(NULL, &p2, i);
free(b);
- return(ret);
+ return (ret);
}
#endif
* the underlying structure instead of doing and encode and decode.
*/
-void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
+void *
+ASN1_item_dup(const ASN1_ITEM *it, void *x)
{
unsigned char *b = NULL;
const unsigned char *p;
void *ret;
if (x == NULL)
- return(NULL);
+ return (NULL);
- i=ASN1_item_i2d(x,&b,it);
+ i = ASN1_item_i2d(x, &b, it);
if (b == NULL) {
- ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE);
- return(NULL);
+ ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE);
+ return (NULL);
}
- p= b;
- ret=ASN1_item_d2i(NULL,&p,i, it);
+ p = b;
+ ret = ASN1_item_d2i(NULL, &p, i, it);
free(b);
- return(ret);
+ return (ret);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include <openssl/asn1.h>
#include <openssl/bn.h>
-/*
+/*
* Code for ENUMERATED type: identical to INTEGER apart from a different tag.
* for comments on encoding see a_int.c
*/
-int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
+int
+ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
{
- int j,k;
+ int j, k;
unsigned int i;
- unsigned char buf[sizeof(long)+1];
+ unsigned char buf[sizeof(long) + 1];
long d;
- a->type=V_ASN1_ENUMERATED;
- if (a->length < (int)(sizeof(long)+1)) {
+ a->type = V_ASN1_ENUMERATED;
+ if (a->length < (int)(sizeof(long) + 1)) {
if (a->data != NULL)
free(a->data);
- if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
- memset((char *)a->data,0,sizeof(long)+1);
+ if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
+ memset((char *)a->data, 0, sizeof(long) + 1);
}
if (a->data == NULL) {
- ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
- return(0);
+ ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE);
+ return (0);
}
- d=v;
+ d = v;
if (d < 0) {
- d= -d;
- a->type=V_ASN1_NEG_ENUMERATED;
+ d = -d;
+ a->type = V_ASN1_NEG_ENUMERATED;
}
- for (i=0; i<sizeof(long); i++) {
- if (d == 0) break;
- buf[i]=(int)d&0xff;
- d>>=8;
+ for (i = 0; i < sizeof(long); i++) {
+ if (d == 0)
+ break;
+ buf[i] = (int)d & 0xff;
+ d >>= 8;
}
- j=0;
- for (k=i-1; k >=0; k--)
- a->data[j++]=buf[k];
- a->length=j;
- return(1);
+ j = 0;
+ for (k = i - 1; k >=0; k--)
+ a->data[j++] = buf[k];
+ a->length = j;
+ return (1);
}
-long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
+long
+ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
{
- int neg=0,i;
- long r=0;
+ int neg = 0, i;
+ long r = 0;
- if (a == NULL) return(0L);
- i=a->type;
+ if (a == NULL)
+ return (0L);
+ i = a->type;
if (i == V_ASN1_NEG_ENUMERATED)
- neg=1;
+ neg = 1;
else if (i != V_ASN1_ENUMERATED)
return -1;
-
+
if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly */
- return(0xffffffffL);
+ return (0xffffffffL);
}
if (a->data == NULL)
return 0;
- for (i=0; i<a->length; i++) {
- r<<=8;
- r|=(unsigned char)a->data[i];
+ for (i = 0; i < a->length; i++) {
+ r <<= 8;
+ r |= (unsigned char)a->data[i];
}
- if (neg) r= -r;
- return(r);
+ if (neg)
+ r = -r;
+ return (r);
}
-ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
+ASN1_ENUMERATED *
+BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
{
ASN1_ENUMERATED *ret;
- int len,j;
+ int len, j;
if (ai == NULL)
- ret=M_ASN1_ENUMERATED_new();
+ ret = M_ASN1_ENUMERATED_new();
else
- ret=ai;
+ ret = ai;
if (ret == NULL) {
- ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
+ ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
- if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED;
- else ret->type=V_ASN1_ENUMERATED;
- j=BN_num_bits(bn);
- len=((j == 0)?0:((j/8)+1));
- if (ret->length < len+4) {
- unsigned char *new_data=realloc(ret->data, len+4);
- if (!new_data)
- {
- ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
+ if (BN_is_negative(bn))
+ ret->type = V_ASN1_NEG_ENUMERATED;
+ else
+ ret->type = V_ASN1_ENUMERATED;
+ j = BN_num_bits(bn);
+ len = ((j == 0) ? 0 : ((j / 8) + 1));
+ if (ret->length < len + 4) {
+ unsigned char *new_data = realloc(ret->data, len + 4);
+ if (!new_data) {
+ ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
goto err;
}
- ret->data=new_data;
+ ret->data = new_data;
}
- ret->length=BN_bn2bin(bn,ret->data);
- return(ret);
+ ret->length = BN_bn2bin(bn, ret->data);
+ return (ret);
+
err:
- if (ret != ai) M_ASN1_ENUMERATED_free(ret);
- return(NULL);
+ if (ret != ai)
+ M_ASN1_ENUMERATED_free(ret);
+ return (NULL);
}
-BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
+BIGNUM *
+ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
{
BIGNUM *ret;
- if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
- ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
- else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1);
- return(ret);
+ if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
+ ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN, ASN1_R_BN_LIB);
+ else if (ai->type == V_ASN1_NEG_ENUMERATED)
+ BN_set_negative(ret, 1);
+ return (ret);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
+ * SUCH DAMAGE.
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#if 0
-int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
+int
+i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
{
- return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
- V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL));
+ return(i2d_ASN1_bytes((ASN1_STRING *)a, pp,
+ V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL));
}
-ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
- unsigned char **pp, long length)
+ASN1_GENERALIZEDTIME *
+d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, unsigned char **pp,
+ long length)
{
- ASN1_GENERALIZEDTIME *ret=NULL;
-
- ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
- V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL);
- if (ret == NULL)
- {
- ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR);
- return(NULL);
+ ASN1_GENERALIZEDTIME *ret = NULL;
+
+ ret = (ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length,
+ V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL);
+ if (ret == NULL) {
+ ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ERR_R_NESTED_ASN1_ERROR);
+ return (NULL);
}
- if (!ASN1_GENERALIZEDTIME_check(ret))
- {
- ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
+ if (!ASN1_GENERALIZEDTIME_check(ret)) {
+ ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ASN1_R_INVALID_TIME_FORMAT);
goto err;
}
- return(ret);
+ return (ret);
+
err:
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_GENERALIZEDTIME_free(ret);
- return(NULL);
+ return (NULL);
}
#endif
-int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
+int
+ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
{
- static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
- static const int max[9]={99, 99,12,31,23,59,59,12,59};
+ static const int min[9] = {0, 0, 1, 1, 0, 0, 0, 0, 0};
+ static const int max[9] = {99, 99, 12, 31, 23, 59, 59, 12, 59};
char *a;
- int n,i,l,o;
+ int n, i, l, o;
- if (d->type != V_ASN1_GENERALIZEDTIME) return(0);
- l=d->length;
- a=(char *)d->data;
- o=0;
+ if (d->type != V_ASN1_GENERALIZEDTIME)
+ return (0);
+ l = d->length;
+ a = (char *)d->data;
+ o = 0;
/* GENERALIZEDTIME is similar to UTCTIME except the year is
* represented as YYYY. This stuff treats everything as a two digit
* field so make first two fields 00 to 99
*/
- if (l < 13) goto err;
- for (i=0; i<7; i++) {
+ if (l < 13)
+ goto err;
+ for (i = 0; i < 7; i++) {
if ((i == 6) && ((a[o] == 'Z') ||
- (a[o] == '+') || (a[o] == '-')))
- { i++; break; }
- if ((a[o] < '0') || (a[o] > '9')) goto err;
+ (a[o] == '+') || (a[o] == '-'))) {
+ i++;
+ break;
+ }
+ if ((a[o] < '0') || (a[o] > '9'))
+ goto err;
n= a[o]-'0';
- if (++o > l) goto err;
+ if (++o > l)
+ goto err;
- if ((a[o] < '0') || (a[o] > '9')) goto err;
- n=(n*10)+ a[o]-'0';
- if (++o > l) goto err;
+ if ((a[o] < '0') || (a[o] > '9'))
+ goto err;
+ n = (n * 10)+ a[o] - '0';
+ if (++o > l)
+ goto err;
- if ((n < min[i]) || (n > max[i])) goto err;
+ if ((n < min[i]) || (n > max[i]))
+ goto err;
}
/* Optional fractional seconds: decimal point followed by one
* or more digits.
*/
- if (a[o] == '.')
- {
- if (++o > l) goto err;
+ if (a[o] == '.') {
+ if (++o > l)
+ goto err;
i = o;
while ((a[o] >= '0') && (a[o] <= '9') && (o <= l))
o++;
/* Must have at least one digit after decimal point */
- if (i == o) goto err;
+ if (i == o)
+ goto err;
}
if (a[o] == 'Z')
o++;
else if ((a[o] == '+') || (a[o] == '-')) {
o++;
- if (o+4 > l) goto err;
- for (i=7; i<9; i++) {
- if ((a[o] < '0') || (a[o] > '9')) goto err;
- n= a[o]-'0';
+ if (o + 4 > l)
+ goto err;
+ for (i = 7; i < 9; i++) {
+ if ((a[o] < '0') || (a[o] > '9'))
+ goto err;
+ n = a[o] - '0';
o++;
- if ((a[o] < '0') || (a[o] > '9')) goto err;
- n=(n*10)+ a[o]-'0';
- if ((n < min[i]) || (n > max[i])) goto err;
+ if ((a[o] < '0') || (a[o] > '9'))
+ goto err;
+ n = (n * 10) + a[o] - '0';
+ if ((n < min[i]) || (n > max[i]))
+ goto err;
o++;
}
} else {
/* Missing time zone information. */
goto err;
}
- return(o == l);
+ return (o == l);
err:
- return(0);
+ return (0);
}
-int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
+int
+ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
{
ASN1_GENERALIZEDTIME t;
- t.type=V_ASN1_GENERALIZEDTIME;
- t.length=strlen(str);
- t.data=(unsigned char *)str;
+ t.type = V_ASN1_GENERALIZEDTIME;
+ t.length = strlen(str);
+ t.data = (unsigned char *)str;
if (ASN1_GENERALIZEDTIME_check(&t)) {
if (s != NULL) {
if (!ASN1_STRING_set((ASN1_STRING *)s,
- (unsigned char *)str,t.length))
+ (unsigned char *)str, t.length))
return 0;
- s->type=V_ASN1_GENERALIZEDTIME;
+ s->type = V_ASN1_GENERALIZEDTIME;
}
- return(1);
- }
- else
- return(0);
+ return (1);
+ } else
+ return (0);
}
-ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
- time_t t)
+ASN1_GENERALIZEDTIME *
+ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, time_t t)
{
- return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0);
+ return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0);
}
-ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
- time_t t, int offset_day, long offset_sec)
+ASN1_GENERALIZEDTIME *
+ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day,
+ long offset_sec)
{
char *p;
struct tm *ts;
struct tm data;
- size_t len = 20;
+ size_t len = 20;
if (s == NULL)
- s=M_ASN1_GENERALIZEDTIME_new();
+ s = M_ASN1_GENERALIZEDTIME_new();
if (s == NULL)
- return(NULL);
+ return (NULL);
- ts=OPENSSL_gmtime(&t, &data);
+ ts = OPENSSL_gmtime(&t, &data);
if (ts == NULL)
- return(NULL);
+ return (NULL);
- if (offset_day || offset_sec) {
+ if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
}
- p=(char *)s->data;
+ p = (char *)s->data;
if ((p == NULL) || ((size_t)s->length < len)) {
- p=malloc(len);
+ p = malloc(len);
if (p == NULL) {
ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
- ERR_R_MALLOC_FAILURE);
- return(NULL);
+ ERR_R_MALLOC_FAILURE);
+ return (NULL);
}
if (s->data != NULL)
free(s->data);
- s->data=(unsigned char *)p;
+ s->data = (unsigned char *)p;
}
- (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
- ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
- s->length=strlen(p);
- s->type=V_ASN1_GENERALIZEDTIME;
- return(s);
+ (void) snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900,
+ ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);
+ s->length = strlen(p);
+ s->type = V_ASN1_GENERALIZEDTIME;
+ return (s);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#ifndef NO_OLD_ASN1
#ifndef OPENSSL_NO_FP_API
-int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
+int
+ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
{
- BIO *b;
- int ret;
+ BIO *b;
+ int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL) {
- ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
- return(0);
+ if ((b = BIO_new(BIO_s_file())) == NULL) {
+ ASN1err(ASN1_F_ASN1_I2D_FP, ERR_R_BUF_LIB);
+ return (0);
}
- BIO_set_fp(b,out,BIO_NOCLOSE);
- ret=ASN1_i2d_bio(i2d,b,x);
- BIO_free(b);
- return(ret);
+ BIO_set_fp(b, out, BIO_NOCLOSE);
+ ret = ASN1_i2d_bio(i2d, b, x);
+ BIO_free(b);
+ return (ret);
}
#endif
-int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
+int
+ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
{
char *b;
unsigned char *p;
- int i,j=0,n,ret=1;
+ int i, j = 0, n, ret = 1;
- n=i2d(x,NULL);
- b=(char *)malloc(n);
+ n = i2d(x, NULL);
+ b = (char *)malloc(n);
if (b == NULL) {
- ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
- return(0);
+ ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
+ return (0);
}
- p=(unsigned char *)b;
- i2d(x,&p);
-
+ p = (unsigned char *)b;
+ i2d(x, &p);
+
for (;;) {
- i=BIO_write(out,&(b[j]),n);
- if (i == n) break;
+ i = BIO_write(out, &(b[j]), n);
+ if (i == n)
+ break;
if (i <= 0) {
- ret=0;
+ ret = 0;
break;
}
- j+=i;
- n-=i;
+ j += i;
+ n -= i;
}
free(b);
- return(ret);
+ return (ret);
}
#endif
#ifndef OPENSSL_NO_FP_API
-int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
+int
+ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
{
- BIO *b;
- int ret;
+ BIO *b;
+ int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL) {
- ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB);
- return(0);
+ if ((b = BIO_new(BIO_s_file())) == NULL) {
+ ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB);
+ return (0);
}
- BIO_set_fp(b,out,BIO_NOCLOSE);
- ret=ASN1_item_i2d_bio(it,b,x);
- BIO_free(b);
- return(ret);
+ BIO_set_fp(b, out, BIO_NOCLOSE);
+ ret = ASN1_item_i2d_bio(it, b, x);
+ BIO_free(b);
+ return (ret);
}
#endif
-int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
+int
+ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
{
unsigned char *b = NULL;
- int i,j=0,n,ret=1;
+ int i, j = 0, n, ret = 1;
n = ASN1_item_i2d(x, &b, it);
if (b == NULL) {
- ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE);
- return(0);
+ ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO, ERR_R_MALLOC_FAILURE);
+ return (0);
}
for (;;) {
- i=BIO_write(out,&(b[j]),n);
- if (i == n) break;
+ i = BIO_write(out, &(b[j]), n);
+ if (i == n)
+ break;
if (i <= 0) {
- ret=0;
+ ret = 0;
break;
}
- j+=i;
- n-=i;
+ j += i;
+ n -= i;
}
free(b);
- return(ret);
+ return (ret);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include <openssl/asn1.h>
#include <openssl/bn.h>
-ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x)
-{ return M_ASN1_INTEGER_dup(x);}
+ASN1_INTEGER *
+ASN1_INTEGER_dup(const ASN1_INTEGER *x)
+{
+ return M_ASN1_INTEGER_dup(x);
+}
-int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
-{
+int
+ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
+{
int neg, ret;
+
/* Compare signs */
neg = x->type & V_ASN1_NEG;
if (neg != (y->type & V_ASN1_NEG)) {
else
return ret;
}
-
-/*
+
+/*
* This converts an ASN1 INTEGER into its content encoding.
* The internal representation is an ASN1_STRING whose data is a big endian
* representation of the value, ignoring the sign. The sign is determined by
- * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
+ * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
*
* Positive integers are no problem: they are almost the same as the DER
* encoding, except if the first byte is >= 0x80 we need to add a zero pad.
*
* Negative integers are a bit trickier...
* The DER representation of negative integers is in 2s complement form.
- * The internal form is converted by complementing each octet and finally
+ * The internal form is converted by complementing each octet and finally
* adding one to the result. This can be done less messily with a little trick.
* If the internal form has trailing zeroes then they will become FF by the
- * complement and 0 by the add one (due to carry) so just copy as many trailing
+ * complement and 0 by the add one (due to carry) so just copy as many trailing
* zeros to the destination as there are in the source. The carry will add one
* to the last none zero octet: so complement this octet and add one and finally
* complement any left over until you get to the start of the string.
* followed by optional zeros isn't padded.
*/
-int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
+int
+i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
{
- int pad=0,ret,i,neg;
- unsigned char *p,*n,pb=0;
+ int pad = 0, ret, i, neg;
+ unsigned char *p, *n, pb = 0;
- if (a == NULL) return(0);
- neg=a->type & V_ASN1_NEG;
+ if (a == NULL)
+ return (0);
+ neg = a->type & V_ASN1_NEG;
if (a->length == 0)
- ret=1;
+ ret = 1;
else {
- ret=a->length;
- i=a->data[0];
+ ret = a->length;
+ i = a->data[0];
if (!neg && (i > 127)) {
- pad=1;
- pb=0;
- } else if(neg) {
- if(i>128) {
- pad=1;
- pb=0xFF;
- } else if(i == 128) {
- /*
- * Special case: if any other bytes non zero we pad:
- * otherwise we don't.
- */
- for(i = 1; i < a->length; i++) if(a->data[i]) {
- pad=1;
- pb=0xFF;
- break;
+ pad = 1;
+ pb = 0;
+ } else if (neg) {
+ if (i > 128) {
+ pad = 1;
+ pb = 0xFF;
+ } else if (i == 128) {
+ /*
+ * Special case: if any other bytes non zero we pad:
+ * otherwise we don't.
+ */
+ for (i = 1; i < a->length; i++) if (a->data[i]) {
+ pad = 1;
+ pb = 0xFF;
+ break;
+ }
}
}
+ ret += pad;
}
- ret+=pad;
- }
- if (pp == NULL) return(ret);
+ if (pp == NULL)
+ return (ret);
p= *pp;
- if (pad) *(p++)=pb;
- if (a->length == 0) *(p++)=0;
- else if (!neg) memcpy(p,a->data,(unsigned int)a->length);
+ if (pad)
+ *(p++) = pb;
+ if (a->length == 0)
+ *(p++) = 0;
+ else if (!neg)
+ memcpy(p, a->data, (unsigned int)a->length);
else {
/* Begin at the end of the encoding */
- n=a->data + a->length - 1;
+ n = a->data + a->length - 1;
p += a->length - 1;
i = a->length;
/* Copy zeros to destination as long as source is zero */
- while(!*n) {
+ while (!*n) {
*(p--) = 0;
n--;
i--;
- }
+ }
/* Complement and increment next octet */
*(p--) = ((*(n--)) ^ 0xff) + 1;
i--;
/* Complement any octets left */
- for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
-}
+ for(; i > 0; i--)
+ *(p--) = *(n--) ^ 0xff;
+ }
- *pp+=ret;
- return(ret);
+ *pp += ret;
+ return (ret);
}
/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
-ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
- long len)
+ASN1_INTEGER *
+c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
{
- ASN1_INTEGER *ret=NULL;
+ ASN1_INTEGER *ret = NULL;
const unsigned char *p, *pend;
- unsigned char *to,*s;
+ unsigned char *to, *s;
int i;
if ((a == NULL) || ((*a) == NULL)) {
- if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
- ret->type=V_ASN1_INTEGER;
- }
- else
- ret=(*a);
+ if ((ret = M_ASN1_INTEGER_new()) == NULL)
+ return (NULL);
+ ret->type = V_ASN1_INTEGER;
+ } else
+ ret = (*a);
p= *pp;
pend = p + len;
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
- s=(unsigned char *)malloc((int)len+1);
+ s = (unsigned char *)malloc((int)len + 1);
if (s == NULL) {
- i=ERR_R_MALLOC_FAILURE;
+ i = ERR_R_MALLOC_FAILURE;
goto err;
}
- to=s;
- if(!len) {
+ to = s;
+ if (!len) {
/* Strictly speaking this is an illegal INTEGER but we
* tolerate it.
*/
- ret->type=V_ASN1_INTEGER;
+ ret->type = V_ASN1_INTEGER;
} else if (*p & 0x80) /* a negative number */ {
- ret->type=V_ASN1_NEG_INTEGER;
+ ret->type = V_ASN1_NEG_INTEGER;
if ((*p == 0xff) && (len != 1)) {
p++;
len--;
* a 1. This is treated separately because it is the only case
* where the number of bytes is larger than len.
*/
- if(!i) {
+ if (!i) {
*s = 1;
s[len] = 0;
len++;
} else {
*(to--) = (*(p--) ^ 0xff) + 1;
i--;
- for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
+ for(; i > 0; i--)
+ *(to--) = *(p--) ^ 0xff;
}
} else {
- ret->type=V_ASN1_INTEGER;
+ ret->type = V_ASN1_INTEGER;
if ((*p == 0) && (len != 1)) {
p++;
len--;
}
- memcpy(s,p,(int)len);
+ memcpy(s, p, (int)len);
}
- if (ret->data != NULL) free(ret->data);
- ret->data=s;
- ret->length=(int)len;
- if (a != NULL) (*a)=ret;
- *pp=pend;
- return(ret);
+ if (ret->data != NULL)
+ free(ret->data);
+ ret->data = s;
+ ret->length = (int)len;
+ if (a != NULL)
+ (*a) = ret;
+ *pp = pend;
+ return (ret);
+
err:
- ASN1err(ASN1_F_C2I_ASN1_INTEGER,i);
+ ASN1err(ASN1_F_C2I_ASN1_INTEGER, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_INTEGER_free(ret);
- return(NULL);
+ return (NULL);
}
* with its MSB set as negative (it doesn't add a padding zero).
*/
-ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
- long length)
+ASN1_INTEGER *
+d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
{
- ASN1_INTEGER *ret=NULL;
+ ASN1_INTEGER *ret = NULL;
const unsigned char *p;
unsigned char *s;
long len;
- int inf,tag,xclass;
+ int inf, tag, xclass;
int i;
if ((a == NULL) || ((*a) == NULL)) {
- if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
- ret->type=V_ASN1_INTEGER;
+ if ((ret = M_ASN1_INTEGER_new()) == NULL)
+ return (NULL);
+ ret->type = V_ASN1_INTEGER;
} else
- ret=(*a);
+ ret = (*a);
- p= *pp;
- inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
+ p = *pp;
+ inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
- i=ASN1_R_BAD_OBJECT_HEADER;
+ i = ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
if (tag != V_ASN1_INTEGER) {
- i=ASN1_R_EXPECTING_AN_INTEGER;
+ i = ASN1_R_EXPECTING_AN_INTEGER;
goto err;
}
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
- s=(unsigned char *)malloc((int)len+1);
+ s = (unsigned char *)malloc((int)len + 1);
if (s == NULL) {
- i=ERR_R_MALLOC_FAILURE;
+ i = ERR_R_MALLOC_FAILURE;
goto err;
}
- ret->type=V_ASN1_INTEGER;
- if(len) {
+ ret->type = V_ASN1_INTEGER;
+ if (len) {
if ((*p == 0) && (len != 1)) {
p++;
len--;
}
- memcpy(s,p,(int)len);
- p+=len;
+ memcpy(s, p, (int)len);
+ p += len;
}
- if (ret->data != NULL) free(ret->data);
- ret->data=s;
- ret->length=(int)len;
- if (a != NULL) (*a)=ret;
- *pp=p;
- return(ret);
+ if (ret->data != NULL)
+ free(ret->data);
+ ret->data = s;
+ ret->length = (int)len;
+ if (a != NULL)
+ (*a) = ret;
+ *pp = p;
+ return (ret);
+
err:
- ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
+ ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_INTEGER_free(ret);
- return(NULL);
+ return (NULL);
}
-int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
+int
+ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
{
- int j,k;
+ int j, k;
unsigned int i;
- unsigned char buf[sizeof(long)+1];
+ unsigned char buf[sizeof(long) + 1];
long d;
- a->type=V_ASN1_INTEGER;
- if (a->length < (int)(sizeof(long)+1)) {
+ a->type = V_ASN1_INTEGER;
+ if (a->length < (int)(sizeof(long) + 1)) {
if (a->data != NULL)
free(a->data);
- if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
- memset((char *)a->data,0,sizeof(long)+1);
+ if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
+ memset((char *)a->data, 0, sizeof(long) + 1);
}
if (a->data == NULL) {
- ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
- return(0);
+ ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE);
+ return (0);
}
- d=v;
+ d = v;
if (d < 0) {
- d= -d;
- a->type=V_ASN1_NEG_INTEGER;
+ d = -d;
+ a->type = V_ASN1_NEG_INTEGER;
}
- for (i=0; i<sizeof(long); i++) {
- if (d == 0) break;
- buf[i]=(int)d&0xff;
- d>>=8;
+ for (i = 0; i < sizeof(long); i++) {
+ if (d == 0)
+ break;
+ buf[i] = (int)d & 0xff;
+ d >>= 8;
}
- j=0;
- for (k=i-1; k >=0; k--)
- a->data[j++]=buf[k];
- a->length=j;
- return(1);
+ j = 0;
+ for (k = i - 1; k >= 0; k--)
+ a->data[j++] = buf[k];
+ a->length = j;
+ return (1);
}
-long ASN1_INTEGER_get(const ASN1_INTEGER *a)
+long
+ASN1_INTEGER_get(const ASN1_INTEGER *a)
{
- int neg=0,i;
- long r=0;
+ int neg = 0, i;
+ long r = 0;
- if (a == NULL) return(0L);
- i=a->type;
+ if (a == NULL)
+ return (0L);
+ i = a->type;
if (i == V_ASN1_NEG_INTEGER)
- neg=1;
+ neg = 1;
else if (i != V_ASN1_INTEGER)
return -1;
-
+
if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly, return all ones */
return -1;
if (a->data == NULL)
return 0;
- for (i=0; i<a->length; i++) {
- r<<=8;
- r|=(unsigned char)a->data[i];
+ for (i = 0; i < a->length; i++) {
+ r <<= 8;
+ r |= (unsigned char)a->data[i];
}
- if (neg) r= -r;
- return(r);
+ if (neg)
+ r = -r;
+ return (r);
}
-ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
+ASN1_INTEGER *
+BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
{
ASN1_INTEGER *ret;
- int len,j;
+ int len, j;
if (ai == NULL)
- ret=M_ASN1_INTEGER_new();
+ ret = M_ASN1_INTEGER_new();
else
- ret=ai;
+ ret = ai;
if (ret == NULL) {
- ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
+ ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (BN_is_negative(bn))
ret->type = V_ASN1_NEG_INTEGER;
- else ret->type=V_ASN1_INTEGER;
- j=BN_num_bits(bn);
- len=((j == 0)?0:((j/8)+1));
- if (ret->length < len+4) {
- unsigned char *new_data=realloc(ret->data, len+4);
+ else
+ ret->type = V_ASN1_INTEGER;
+ j = BN_num_bits(bn);
+ len = ((j == 0) ? 0 : ((j / 8) + 1));
+ if (ret->length < len + 4) {
+ unsigned char *new_data = realloc(ret->data, len + 4);
if (!new_data) {
- ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
+ ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
goto err;
}
- ret->data=new_data;
+ ret->data = new_data;
}
- ret->length=BN_bn2bin(bn,ret->data);
+ ret->length = BN_bn2bin(bn, ret->data);
+
/* Correct zero case */
- if(!ret->length) {
+ if (!ret->length) {
ret->data[0] = 0;
ret->length = 1;
}
- return(ret);
+ return (ret);
+
err:
- if (ret != ai) M_ASN1_INTEGER_free(ret);
- return(NULL);
+ if (ret != ai)
+ M_ASN1_INTEGER_free(ret);
+ return (NULL);
}
-BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
+BIGNUM *
+ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
{
BIGNUM *ret;
- if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
- ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
- else if(ai->type == V_ASN1_NEG_INTEGER)
+ if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
+ ASN1err(ASN1_F_ASN1_INTEGER_TO_BN, ASN1_R_BN_LIB);
+ else if (ai->type == V_ASN1_NEG_INTEGER)
BN_set_negative(ret, 1);
- return(ret);
+ return (ret);
}
IMPLEMENT_STACK_OF(ASN1_INTEGER)
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
#include <openssl/asn1.h>
static int traverse_string(const unsigned char *p, int len, int inform,
- int (*rfunc)(unsigned long value, void *in), void *arg);
+ int (*rfunc)(unsigned long value, void *in), void *arg);
static int in_utf8(unsigned long value, void *arg);
static int out_utf8(unsigned long value, void *arg);
static int type_str(unsigned long value, void *arg);
* The 'ncopy' form checks minimum and maximum size limits too.
*/
-int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
- int inform, unsigned long mask)
+int
+ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
+ int inform, unsigned long mask)
{
return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
}
-int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
- int inform, unsigned long mask,
- long minsize, long maxsize)
+int
+ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
+ int inform, unsigned long mask,
+ long minsize, long maxsize)
{
int str_type;
int ret;
unsigned char *p;
int nchar;
char strbuf[32];
- int (*cpyfunc)(unsigned long,void *) = NULL;
- if(len == -1) len = strlen((const char *)in);
- if(!mask) mask = DIRSTRING_TYPE;
+ int (*cpyfunc)(unsigned long, void *) = NULL;
+
+ if (len == -1)
+ len = strlen((const char *)in);
+ if (!mask)
+ mask = DIRSTRING_TYPE;
/* First do a string check and work out the number of characters */
- switch(inform) {
+ switch (inform) {
- case MBSTRING_BMP:
- if(len & 1) {
+ case MBSTRING_BMP:
+ if (len & 1) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
- ASN1_R_INVALID_BMPSTRING_LENGTH);
+ ASN1_R_INVALID_BMPSTRING_LENGTH);
return -1;
}
nchar = len >> 1;
break;
- case MBSTRING_UNIV:
- if(len & 3) {
+ case MBSTRING_UNIV:
+ if (len & 3) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
- ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
+ ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
return -1;
}
nchar = len >> 2;
break;
- case MBSTRING_UTF8:
+ case MBSTRING_UTF8:
nchar = 0;
/* This counts the characters and does utf8 syntax checking */
ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
- if(ret < 0) {
+ if (ret < 0) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
- ASN1_R_INVALID_UTF8STRING);
+ ASN1_R_INVALID_UTF8STRING);
return -1;
}
break;
- case MBSTRING_ASC:
+ case MBSTRING_ASC:
nchar = len;
break;
- default:
+ default:
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT);
return -1;
}
- if((minsize > 0) && (nchar < minsize)) {
+ if ((minsize > 0) && (nchar < minsize)) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT);
(void) snprintf(strbuf, sizeof strbuf, "%ld", minsize);
ERR_add_error_data(2, "minsize=", strbuf);
return -1;
}
- if((maxsize > 0) && (nchar > maxsize)) {
+ if ((maxsize > 0) && (nchar > maxsize)) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG);
(void) snprintf(strbuf, sizeof strbuf, "%ld", maxsize);
ERR_add_error_data(2, "maxsize=", strbuf);
}
/* Now work out minimal type (if any) */
- if(traverse_string(in, len, inform, type_str, &mask) < 0) {
+ if (traverse_string(in, len, inform, type_str, &mask) < 0) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS);
return -1;
}
/* Now work out output format and string type */
outform = MBSTRING_ASC;
- if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
- else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
- else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
- else if(mask & B_ASN1_BMPSTRING) {
+ if (mask & B_ASN1_PRINTABLESTRING)
+ str_type = V_ASN1_PRINTABLESTRING;
+ else if (mask & B_ASN1_IA5STRING)
+ str_type = V_ASN1_IA5STRING;
+ else if (mask & B_ASN1_T61STRING)
+ str_type = V_ASN1_T61STRING;
+ else if (mask & B_ASN1_BMPSTRING) {
str_type = V_ASN1_BMPSTRING;
outform = MBSTRING_BMP;
- } else if(mask & B_ASN1_UNIVERSALSTRING) {
+ } else if (mask & B_ASN1_UNIVERSALSTRING) {
str_type = V_ASN1_UNIVERSALSTRING;
outform = MBSTRING_UNIV;
} else {
str_type = V_ASN1_UTF8STRING;
outform = MBSTRING_UTF8;
}
- if(!out) return str_type;
- if(*out) {
+ if (!out)
+ return str_type;
+ if (*out) {
free_out = 0;
dest = *out;
- if(dest->data) {
+ if (dest->data) {
dest->length = 0;
free(dest->data);
dest->data = NULL;
} else {
free_out = 1;
dest = ASN1_STRING_type_new(str_type);
- if(!dest) {
+ if (!dest) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
- ERR_R_MALLOC_FAILURE);
+ ERR_R_MALLOC_FAILURE);
return -1;
}
*out = dest;
}
/* If both the same type just copy across */
- if(inform == outform) {
- if(!ASN1_STRING_set(dest, in, len)) {
- ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE);
+ if (inform == outform) {
+ if (!ASN1_STRING_set(dest, in, len)) {
+ ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
+ ERR_R_MALLOC_FAILURE);
return -1;
}
return str_type;
- }
+ }
/* Work out how much space the destination will need */
- switch(outform) {
- case MBSTRING_ASC:
+ switch (outform) {
+ case MBSTRING_ASC:
outlen = nchar;
cpyfunc = cpy_asc;
break;
- case MBSTRING_BMP:
+ case MBSTRING_BMP:
outlen = nchar << 1;
cpyfunc = cpy_bmp;
break;
- case MBSTRING_UNIV:
+ case MBSTRING_UNIV:
outlen = nchar << 2;
cpyfunc = cpy_univ;
break;
- case MBSTRING_UTF8:
+ case MBSTRING_UTF8:
outlen = 0;
traverse_string(in, len, inform, out_utf8, &outlen);
cpyfunc = cpy_utf8;
break;
}
- if(!(p = malloc(outlen + 1))) {
- if(free_out) ASN1_STRING_free(dest);
- ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE);
+ if (!(p = malloc(outlen + 1))) {
+ if (free_out)
+ ASN1_STRING_free(dest);
+ ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE);
return -1;
}
dest->length = outlen;
dest->data = p;
p[outlen] = 0;
traverse_string(in, len, inform, cpyfunc, &p);
- return str_type;
+ return str_type;
}
/* This function traverses a string and passes the value of each character
* to an optional function along with a void * argument.
*/
-static int traverse_string(const unsigned char *p, int len, int inform,
- int (*rfunc)(unsigned long value, void *in), void *arg)
+static int
+traverse_string(const unsigned char *p, int len, int inform,
+ int (*rfunc)(unsigned long value, void *in), void *arg)
{
unsigned long value;
int ret;
- while(len) {
- if(inform == MBSTRING_ASC) {
+ while (len) {
+ if (inform == MBSTRING_ASC) {
value = *p++;
len--;
- } else if(inform == MBSTRING_BMP) {
+ } else if (inform == MBSTRING_BMP) {
value = *p++ << 8;
value |= *p++;
len -= 2;
- } else if(inform == MBSTRING_UNIV) {
+ } else if (inform == MBSTRING_UNIV) {
value = ((unsigned long)*p++) << 24;
value |= ((unsigned long)*p++) << 16;
value |= *p++ << 8;
len -= 4;
} else {
ret = UTF8_getc(p, len, &value);
- if(ret < 0) return -1;
- len -= ret;
+ if (ret < 0) return -1;
+ len -= ret;
p += ret;
}
- if(rfunc) {
+ if (rfunc) {
ret = rfunc(value, arg);
- if(ret <= 0) return ret;
+ if (ret <= 0)
+ return ret;
}
}
return 1;
/* Just count number of characters */
-static int in_utf8(unsigned long value, void *arg)
+static int
+in_utf8(unsigned long value, void *arg)
{
int *nchar;
nchar = arg;
/* Determine size of output as a UTF8 String */
-static int out_utf8(unsigned long value, void *arg)
+static int
+out_utf8(unsigned long value, void *arg)
{
int *outlen;
outlen = arg;
* supplied "mask".
*/
-static int type_str(unsigned long value, void *arg)
+static int
+type_str(unsigned long value, void *arg)
{
unsigned long types;
+
types = *((unsigned long *)arg);
- if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
- types &= ~B_ASN1_PRINTABLESTRING;
- if((types & B_ASN1_IA5STRING) && (value > 127))
- types &= ~B_ASN1_IA5STRING;
- if((types & B_ASN1_T61STRING) && (value > 0xff))
- types &= ~B_ASN1_T61STRING;
- if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
- types &= ~B_ASN1_BMPSTRING;
- if(!types) return -1;
+ if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
+ types &= ~B_ASN1_PRINTABLESTRING;
+ if ((types & B_ASN1_IA5STRING) && (value > 127))
+ types &= ~B_ASN1_IA5STRING;
+ if ((types & B_ASN1_T61STRING) && (value > 0xff))
+ types &= ~B_ASN1_T61STRING;
+ if ((types & B_ASN1_BMPSTRING) && (value > 0xffff))
+ types &= ~B_ASN1_BMPSTRING;
+ if (!types)
+ return -1;
*((unsigned long *)arg) = types;
return 1;
}
/* Copy one byte per character ASCII like strings */
-static int cpy_asc(unsigned long value, void *arg)
+static int
+cpy_asc(unsigned long value, void *arg)
{
unsigned char **p, *q;
+
p = arg;
q = *p;
*q = (unsigned char) value;
/* Copy two byte per character BMPStrings */
-static int cpy_bmp(unsigned long value, void *arg)
+static int
+cpy_bmp(unsigned long value, void *arg)
{
unsigned char **p, *q;
+
p = arg;
q = *p;
*q++ = (unsigned char) ((value >> 8) & 0xff);
/* Copy four byte per character UniversalStrings */
-static int cpy_univ(unsigned long value, void *arg)
+static int
+cpy_univ(unsigned long value, void *arg)
{
unsigned char **p, *q;
+
p = arg;
q = *p;
*q++ = (unsigned char) ((value >> 24) & 0xff);
/* Copy to a UTF8String */
-static int cpy_utf8(unsigned long value, void *arg)
+static int
+cpy_utf8(unsigned long value, void *arg)
{
unsigned char **p;
+
int ret;
p = arg;
/* We already know there is enough room so pass 0xff as the length */
}
/* Return 1 if the character is permitted in a PrintableString */
-static int is_printable(unsigned long value)
+static int
+is_printable(unsigned long value)
{
int ch;
- if(value > 0x7f) return 0;
- ch = (int) value;
- /* Note: we can't use 'isalnum' because certain accented
+
+ if (value > 0x7f) return 0;
+ ch = (int)value;
+ /* Note: we can't use 'isalnum' because certain accented
* characters may count as alphanumeric in some environments.
*/
- if((ch >= 'a') && (ch <= 'z')) return 1;
- if((ch >= 'A') && (ch <= 'Z')) return 1;
- if((ch >= '0') && (ch <= '9')) return 1;
- if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
+ if ((ch >= 'a') && (ch <= 'z'))
+ return 1;
+ if ((ch >= 'A') && (ch <= 'Z'))
+ return 1;
+ if ((ch >= '0') && (ch <= '9'))
+ return 1;
+ if ((ch == ' ') || strchr("'()+,-./:=?", ch))
+ return 1;
return 0;
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include <openssl/objects.h>
#include <openssl/bn.h>
-int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
+int
+i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
{
unsigned char *p;
int objsize;
- if ((a == NULL) || (a->data == NULL)) return(0);
+ if ((a == NULL) || (a->data == NULL))
+ return (0);
- objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT);
- if (pp == NULL) return objsize;
+ objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
+ if (pp == NULL)
+ return objsize;
- p= *pp;
- ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
- memcpy(p,a->data,a->length);
- p+=a->length;
+ p = *pp;
+ ASN1_put_object(&p, 0,a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
+ memcpy(p, a->data, a->length);
+ p += a->length;
- *pp=p;
- return(objsize);
+ *pp = p;
+ return (objsize);
}
-int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
+int
+a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
{
- int i,first,len=0,c, use_bn;
+ int i, first, len = 0, c, use_bn;
char ftmp[24], *tmp = ftmp;
int tmpsize = sizeof ftmp;
const char *p;
BIGNUM *bl = NULL;
if (num == 0)
- return(0);
+ return (0);
else if (num == -1)
- num=strlen(buf);
+ num = strlen(buf);
- p=buf;
- c= *(p++);
+ p = buf;
+ c = *(p++);
num--;
if ((c >= '0') && (c <= '2')) {
first= c-'0';
} else {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE);
goto err;
}
if (num <= 0) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER);
goto err;
}
- c= *(p++);
+ c = *(p++);
num--;
for (;;) {
- if (num <= 0) break;
+ if (num <= 0)
+ break;
if ((c != '.') && (c != ' ')) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT,
+ ASN1_R_INVALID_SEPARATOR);
goto err;
}
- l=0;
+ l = 0;
use_bn = 0;
for (;;) {
- if (num <= 0) break;
+ if (num <= 0)
+ break;
num--;
- c= *(p++);
+ c = *(p++);
if ((c == ' ') || (c == '.'))
break;
if ((c < '0') || (c > '9')) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT,
+ ASN1_R_INVALID_DIGIT);
goto err;
}
if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
goto err;
}
if (use_bn) {
- if (!BN_mul_word(bl, 10L)
- || !BN_add_word(bl, c-'0'))
+ if (!BN_mul_word(bl, 10L) ||
+ !BN_add_word(bl, c-'0'))
goto err;
- }
- else
- l=l*10L+(long)(c-'0');
+ } else
+ l = l * 10L + (long)(c - '0');
}
if (len == 0) {
if ((first < 2) && (l >= 40)) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT,
+ ASN1_R_SECOND_NUMBER_TOO_LARGE);
goto err;
}
if (use_bn) {
if (!BN_add_word(bl, first * 40))
goto err;
- }
- else
- l+=(long)first*40;
+ } else
+ l += (long)first * 40;
}
- i=0;
+ i = 0;
if (use_bn) {
int blsize;
blsize = BN_num_bits(bl);
- blsize = (blsize + 6)/7;
+ blsize = (blsize + 6) / 7;
if (blsize > tmpsize) {
if (tmp != ftmp)
free(tmp);
if (!tmp)
goto err;
}
- while(blsize--)
+ while (blsize--)
tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L);
} else {
-
+
for (;;) {
- tmp[i++]=(unsigned char)l&0x7f;
- l>>=7L;
- if (l == 0L) break;
+ tmp[i++] = (unsigned char)l & 0x7f;
+ l >>= 7L;
+ if (l == 0L)
+ break;
}
}
if (out != NULL) {
- if (len+i > olen) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
+ if (len + i > olen) {
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT,
+ ASN1_R_BUFFER_TOO_SMALL);
goto err;
}
while (--i > 0)
- out[len++]=tmp[i]|0x80;
- out[len++]=tmp[0];
- }
- else
- len+=i;
+ out[len++] = tmp[i]|0x80;
+ out[len++] = tmp[0];
+ } else
+ len += i;
}
if (tmp != ftmp)
free(tmp);
if (bl)
BN_free(bl);
- return(len);
+ return (len);
+
err:
if (tmp != ftmp)
free(tmp);
if (bl)
BN_free(bl);
- return(0);
+ return (0);
}
-int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
+int
+i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
{
return OBJ_obj2txt(buf, buf_len, a, 0);
}
-int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
+int
+i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
{
char buf[80], *p = buf;
int i;
if ((a == NULL) || (a->data == NULL))
- return(BIO_write(bp,"NULL",4));
- i=i2t_ASN1_OBJECT(buf,sizeof buf,a);
+ return(BIO_write(bp, "NULL",4));
+ i = i2t_ASN1_OBJECT(buf, sizeof buf, a);
if (i > (int)(sizeof(buf) - 1)) {
p = malloc(i + 1);
if (!p)
return -1;
- i2t_ASN1_OBJECT(p,i + 1,a);
+ i2t_ASN1_OBJECT(p, i + 1, a);
}
if (i <= 0)
return BIO_write(bp, "<INVALID>", 9);
- BIO_write(bp,p,i);
+ BIO_write(bp, p, i);
if (p != buf)
free(p);
- return(i);
+ return (i);
}
-ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
- long length)
+ASN1_OBJECT *
+d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length)
{
const unsigned char *p;
long len;
- int tag,xclass;
- int inf,i;
+ int tag, xclass;
+ int inf, i;
ASN1_OBJECT *ret = NULL;
- p= *pp;
- inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
+
+ p = *pp;
+ inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
- i=ASN1_R_BAD_OBJECT_HEADER;
+ i = ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
if (tag != V_ASN1_OBJECT) {
- i=ASN1_R_EXPECTING_AN_OBJECT;
+ i = ASN1_R_EXPECTING_AN_OBJECT;
goto err;
}
ret = c2i_ASN1_OBJECT(a, &p, len);
- if(ret) *pp = p;
+ if (ret)
+ *pp = p;
return ret;
+
err:
- ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
- return(NULL);
+ ASN1err(ASN1_F_D2I_ASN1_OBJECT, i);
+ return (NULL);
}
-ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
- long len)
+
+ASN1_OBJECT *
+c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
{
- ASN1_OBJECT *ret=NULL;
+ ASN1_OBJECT *ret = NULL;
const unsigned char *p;
unsigned char *data;
int i;
+
/* Sanity check OID encoding: can't have leading 0x80 in
* subidentifiers, see: X.690 8.19.2
*/
for (i = 0, p = *pp; i < len; i++, p++) {
if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
- ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING);
+ ASN1err(ASN1_F_C2I_ASN1_OBJECT,
+ ASN1_R_INVALID_OBJECT_ENCODING);
return NULL;
}
}
/* only the ASN1_OBJECTs from the 'table' will have values
* for ->sn or ->ln */
if ((a == NULL) || ((*a) == NULL) ||
- !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
- if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
- }
- else ret=(*a);
+ !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
+ if ((ret = ASN1_OBJECT_new()) == NULL)
+ return (NULL);
+ } else
+ ret = (*a);
- p= *pp;
+ p = *pp;
/* detach data from object */
data = (unsigned char *)ret->data;
ret->data = NULL;
/* once detached we can change it */
if ((data == NULL) || (ret->length < len)) {
- ret->length=0;
- if (data != NULL) free(data);
- data=(unsigned char *)malloc(len ? (int)len : 1);
- if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; }
- ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
+ ret->length = 0;
+ if (data != NULL)
+ free(data);
+ data = (unsigned char *)malloc(len ? (int)len : 1);
+ if (data == NULL) {
+ i = ERR_R_MALLOC_FAILURE;
+ goto err;
+ }
+ ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
}
- memcpy(data,p,(int)len);
+ memcpy(data, p, (int)len);
/* reattach data to object, after which it remains const */
- ret->data =data;
- ret->length=(int)len;
- ret->sn=NULL;
- ret->ln=NULL;
+ ret->data = data;
+ ret->length = (int)len;
+ ret->sn = NULL;
+ ret->ln = NULL;
/* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
- p+=len;
+ p += len;
+
+ if (a != NULL)
+ (*a) = ret;
+ *pp = p;
+ return (ret);
- if (a != NULL) (*a)=ret;
- *pp=p;
- return(ret);
err:
- ASN1err(ASN1_F_C2I_ASN1_OBJECT,i);
+ ASN1err(ASN1_F_C2I_ASN1_OBJECT, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
ASN1_OBJECT_free(ret);
- return(NULL);
+ return (NULL);
}
-ASN1_OBJECT *ASN1_OBJECT_new(void)
+ASN1_OBJECT *
+ASN1_OBJECT_new(void)
{
ASN1_OBJECT *ret;
- ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
+ ret = (ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
if (ret == NULL) {
- ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
- return(NULL);
+ ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
+ return (NULL);
}
- ret->length=0;
- ret->data=NULL;
- ret->nid=0;
- ret->sn=NULL;
- ret->ln=NULL;
- ret->flags=ASN1_OBJECT_FLAG_DYNAMIC;
- return(ret);
+ ret->length = 0;
+ ret->data = NULL;
+ ret->nid = 0;
+ ret->sn = NULL;
+ ret->ln = NULL;
+ ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
+ return (ret);
}
-void ASN1_OBJECT_free(ASN1_OBJECT *a)
+void
+ASN1_OBJECT_free(ASN1_OBJECT *a)
{
- if (a == NULL) return;
+ if (a == NULL)
+ return;
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
- if (a->sn != NULL) free((void *)a->sn);
- if (a->ln != NULL) free((void *)a->ln);
+ if (a->sn != NULL)
+ free((void *)a->sn);
+ if (a->ln != NULL)
+ free((void *)a->ln);
#endif
- a->sn=a->ln=NULL;
+ a->sn = a->ln = NULL;
}
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
- if (a->data != NULL) free((void *)a->data);
- a->data=NULL;
- a->length=0;
+ if (a->data != NULL)
+ free((void *)a->data);
+ a->data = NULL;
+ a->length = 0;
}
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
free(a);
}
-ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
- const char *sn, const char *ln)
+ASN1_OBJECT *
+ASN1_OBJECT_create(int nid, unsigned char *data, int len,
+ const char *sn, const char *ln)
{
ASN1_OBJECT o;
- o.sn=sn;
- o.ln=ln;
- o.data=data;
- o.nid=nid;
- o.length=len;
- o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
- ASN1_OBJECT_FLAG_DYNAMIC_DATA;
- return(OBJ_dup(&o));
+ o.sn = sn;
+ o.ln = ln;
+ o.data = data;
+ o.nid = nid;
+ o.length = len;
+ o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
+ ASN1_OBJECT_FLAG_DYNAMIC_DATA;
+ return (OBJ_dup(&o));
}
IMPLEMENT_STACK_OF(ASN1_OBJECT)
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include "cryptlib.h"
#include <openssl/asn1.h>
-ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
-{ return M_ASN1_OCTET_STRING_dup(x); }
-
-int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b)
-{ return M_ASN1_OCTET_STRING_cmp(a, b); }
+ASN1_OCTET_STRING *
+ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
+{
+ return M_ASN1_OCTET_STRING_dup(x);
+}
-int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
-{ return M_ASN1_OCTET_STRING_set(x, d, len); }
+int
+ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b)
+{
+ return M_ASN1_OCTET_STRING_cmp(a, b);
+}
+int
+ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
+{
+ return M_ASN1_OCTET_STRING_set(x, d, len);
+}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include "cryptlib.h"
#include <openssl/asn1.h>
-int ASN1_PRINTABLE_type(const unsigned char *s, int len)
+int
+ASN1_PRINTABLE_type(const unsigned char *s, int len)
{
int c;
- int ia5=0;
- int t61=0;
+ int ia5 = 0;
+ int t61 = 0;
- if (len <= 0) len= -1;
- if (s == NULL) return(V_ASN1_PRINTABLESTRING);
+ if (len <= 0)
+ len = -1;
+ if (s == NULL)
+ return (V_ASN1_PRINTABLESTRING);
while ((*s) && (len-- != 0)) {
c= *(s++);
- if (!( ((c >= 'a') && (c <= 'z')) ||
- ((c >= 'A') && (c <= 'Z')) ||
- (c == ' ') ||
- ((c >= '0') && (c <= '9')) ||
- (c == ' ') || (c == '\'') ||
- (c == '(') || (c == ')') ||
- (c == '+') || (c == ',') ||
- (c == '-') || (c == '.') ||
- (c == '/') || (c == ':') ||
- (c == '=') || (c == '?')))
- ia5=1;
- if (c&0x80)
- t61=1;
+ if (!(((c >= 'a') && (c <= 'z')) ||
+ ((c >= 'A') && (c <= 'Z')) ||
+ (c == ' ') ||
+ ((c >= '0') && (c <= '9')) ||
+ (c == ' ') || (c == '\'') ||
+ (c == '(') || (c == ')') ||
+ (c == '+') || (c == ',') ||
+ (c == '-') || (c == '.') ||
+ (c == '/') || (c == ':') ||
+ (c == '=') || (c == '?')))
+ ia5 = 1;
+ if (c & 0x80)
+ t61 = 1;
}
- if (t61) return(V_ASN1_T61STRING);
- if (ia5) return(V_ASN1_IA5STRING);
- return(V_ASN1_PRINTABLESTRING);
+ if (t61)
+ return (V_ASN1_T61STRING);
+ if (ia5)
+ return (V_ASN1_IA5STRING);
+ return (V_ASN1_PRINTABLESTRING);
}
-int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
+int
+ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
{
int i;
unsigned char *p;
- if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
- if ((s->length%4) != 0) return(0);
- p=s->data;
- for (i=0; i<s->length; i+=4) {
+ if (s->type != V_ASN1_UNIVERSALSTRING)
+ return (0);
+ if ((s->length % 4) != 0)
+ return (0);
+ p = s->data;
+ for (i = 0; i < s->length; i += 4) {
if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
break;
else
- p+=4;
+ p += 4;
}
- if (i < s->length) return(0);
- p=s->data;
- for (i=3; i<s->length; i+=4) {
- *(p++)=s->data[i];
+ if (i < s->length)
+ return (0);
+ p = s->data;
+ for (i = 3; i < s->length; i += 4) {
+ *(p++) = s->data[i];
}
- *(p)='\0';
- s->length/=4;
- s->type=ASN1_PRINTABLE_type(s->data,s->length);
- return(1);
+ *(p) = '\0';
+ s->length /= 4;
+ s->type = ASN1_PRINTABLE_type(s->data, s->length);
+ return (1);
}
int
i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
{
- int ret, j,bits, len;
+ int ret, j, bits, len;
unsigned char *p, *d;
if (a == NULL)
if (a == NULL)
return 0;
- a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
+ a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear, set on write */
if ((a->length < (w + 1)) || (a->data == NULL)) {
if (!value)
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include <openssl/buffer.h>
#include <openssl/x509.h>
-int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
- unsigned char *md, unsigned int *len)
+int
+ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
+ unsigned char *md, unsigned int *len)
{
int i;
unsigned char *str = NULL;
- i=ASN1_item_i2d(asn,&str, it);
- if (!str) return(0);
+ i = ASN1_item_i2d(asn, &str, it);
+ if (!str)
+ return (0);
if (!EVP_Digest(str, i, md, len, type, NULL))
return 0;
free(str);
- return(1);
+ return (1);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#ifndef NO_OLD_ASN1
-void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
+void *
+ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
{
- unsigned char *b,*p;
+ unsigned char *b, *p;
const unsigned char *p2;
int i;
char *ret;
if (x == NULL)
- return(NULL);
+ return (NULL);
- i=i2d(x,NULL);
- b=malloc(i+10);
+ i = i2d(x, NULL);
+ b = malloc(i + 10);
if (b == NULL) {
- ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE);
- return(NULL);
+ ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE);
+ return (NULL);
}
- p= b;
- i=i2d(x,&p);
- p2= b;
- ret=d2i(NULL,&p2,i);
+ p = b;
+ i = i2d(x, &p);
+ p2 = b;
+ ret = d2i(NULL, &p2, i);
free(b);
- return(ret);
+ return (ret);
}
#endif
* the underlying structure instead of doing and encode and decode.
*/
-void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
+void *
+ASN1_item_dup(const ASN1_ITEM *it, void *x)
{
unsigned char *b = NULL;
const unsigned char *p;
void *ret;
if (x == NULL)
- return(NULL);
+ return (NULL);
- i=ASN1_item_i2d(x,&b,it);
+ i = ASN1_item_i2d(x, &b, it);
if (b == NULL) {
- ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE);
- return(NULL);
+ ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE);
+ return (NULL);
}
- p= b;
- ret=ASN1_item_d2i(NULL,&p,i, it);
+ p = b;
+ ret = ASN1_item_d2i(NULL, &p, i, it);
free(b);
- return(ret);
+ return (ret);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include <openssl/asn1.h>
#include <openssl/bn.h>
-/*
+/*
* Code for ENUMERATED type: identical to INTEGER apart from a different tag.
* for comments on encoding see a_int.c
*/
-int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
+int
+ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
{
- int j,k;
+ int j, k;
unsigned int i;
- unsigned char buf[sizeof(long)+1];
+ unsigned char buf[sizeof(long) + 1];
long d;
- a->type=V_ASN1_ENUMERATED;
- if (a->length < (int)(sizeof(long)+1)) {
+ a->type = V_ASN1_ENUMERATED;
+ if (a->length < (int)(sizeof(long) + 1)) {
if (a->data != NULL)
free(a->data);
- if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
- memset((char *)a->data,0,sizeof(long)+1);
+ if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
+ memset((char *)a->data, 0, sizeof(long) + 1);
}
if (a->data == NULL) {
- ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
- return(0);
+ ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE);
+ return (0);
}
- d=v;
+ d = v;
if (d < 0) {
- d= -d;
- a->type=V_ASN1_NEG_ENUMERATED;
+ d = -d;
+ a->type = V_ASN1_NEG_ENUMERATED;
}
- for (i=0; i<sizeof(long); i++) {
- if (d == 0) break;
- buf[i]=(int)d&0xff;
- d>>=8;
+ for (i = 0; i < sizeof(long); i++) {
+ if (d == 0)
+ break;
+ buf[i] = (int)d & 0xff;
+ d >>= 8;
}
- j=0;
- for (k=i-1; k >=0; k--)
- a->data[j++]=buf[k];
- a->length=j;
- return(1);
+ j = 0;
+ for (k = i - 1; k >=0; k--)
+ a->data[j++] = buf[k];
+ a->length = j;
+ return (1);
}
-long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
+long
+ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
{
- int neg=0,i;
- long r=0;
+ int neg = 0, i;
+ long r = 0;
- if (a == NULL) return(0L);
- i=a->type;
+ if (a == NULL)
+ return (0L);
+ i = a->type;
if (i == V_ASN1_NEG_ENUMERATED)
- neg=1;
+ neg = 1;
else if (i != V_ASN1_ENUMERATED)
return -1;
-
+
if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly */
- return(0xffffffffL);
+ return (0xffffffffL);
}
if (a->data == NULL)
return 0;
- for (i=0; i<a->length; i++) {
- r<<=8;
- r|=(unsigned char)a->data[i];
+ for (i = 0; i < a->length; i++) {
+ r <<= 8;
+ r |= (unsigned char)a->data[i];
}
- if (neg) r= -r;
- return(r);
+ if (neg)
+ r = -r;
+ return (r);
}
-ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
+ASN1_ENUMERATED *
+BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
{
ASN1_ENUMERATED *ret;
- int len,j;
+ int len, j;
if (ai == NULL)
- ret=M_ASN1_ENUMERATED_new();
+ ret = M_ASN1_ENUMERATED_new();
else
- ret=ai;
+ ret = ai;
if (ret == NULL) {
- ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
+ ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
- if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED;
- else ret->type=V_ASN1_ENUMERATED;
- j=BN_num_bits(bn);
- len=((j == 0)?0:((j/8)+1));
- if (ret->length < len+4) {
- unsigned char *new_data=realloc(ret->data, len+4);
- if (!new_data)
- {
- ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
+ if (BN_is_negative(bn))
+ ret->type = V_ASN1_NEG_ENUMERATED;
+ else
+ ret->type = V_ASN1_ENUMERATED;
+ j = BN_num_bits(bn);
+ len = ((j == 0) ? 0 : ((j / 8) + 1));
+ if (ret->length < len + 4) {
+ unsigned char *new_data = realloc(ret->data, len + 4);
+ if (!new_data) {
+ ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
goto err;
}
- ret->data=new_data;
+ ret->data = new_data;
}
- ret->length=BN_bn2bin(bn,ret->data);
- return(ret);
+ ret->length = BN_bn2bin(bn, ret->data);
+ return (ret);
+
err:
- if (ret != ai) M_ASN1_ENUMERATED_free(ret);
- return(NULL);
+ if (ret != ai)
+ M_ASN1_ENUMERATED_free(ret);
+ return (NULL);
}
-BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
+BIGNUM *
+ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
{
BIGNUM *ret;
- if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
- ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
- else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1);
- return(ret);
+ if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
+ ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN, ASN1_R_BN_LIB);
+ else if (ai->type == V_ASN1_NEG_ENUMERATED)
+ BN_set_negative(ret, 1);
+ return (ret);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
+ * SUCH DAMAGE.
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#if 0
-int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
+int
+i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
{
- return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
- V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL));
+ return(i2d_ASN1_bytes((ASN1_STRING *)a, pp,
+ V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL));
}
-ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
- unsigned char **pp, long length)
+ASN1_GENERALIZEDTIME *
+d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, unsigned char **pp,
+ long length)
{
- ASN1_GENERALIZEDTIME *ret=NULL;
-
- ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
- V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL);
- if (ret == NULL)
- {
- ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR);
- return(NULL);
+ ASN1_GENERALIZEDTIME *ret = NULL;
+
+ ret = (ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length,
+ V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL);
+ if (ret == NULL) {
+ ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ERR_R_NESTED_ASN1_ERROR);
+ return (NULL);
}
- if (!ASN1_GENERALIZEDTIME_check(ret))
- {
- ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
+ if (!ASN1_GENERALIZEDTIME_check(ret)) {
+ ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ASN1_R_INVALID_TIME_FORMAT);
goto err;
}
- return(ret);
+ return (ret);
+
err:
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_GENERALIZEDTIME_free(ret);
- return(NULL);
+ return (NULL);
}
#endif
-int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
+int
+ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
{
- static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
- static const int max[9]={99, 99,12,31,23,59,59,12,59};
+ static const int min[9] = {0, 0, 1, 1, 0, 0, 0, 0, 0};
+ static const int max[9] = {99, 99, 12, 31, 23, 59, 59, 12, 59};
char *a;
- int n,i,l,o;
+ int n, i, l, o;
- if (d->type != V_ASN1_GENERALIZEDTIME) return(0);
- l=d->length;
- a=(char *)d->data;
- o=0;
+ if (d->type != V_ASN1_GENERALIZEDTIME)
+ return (0);
+ l = d->length;
+ a = (char *)d->data;
+ o = 0;
/* GENERALIZEDTIME is similar to UTCTIME except the year is
* represented as YYYY. This stuff treats everything as a two digit
* field so make first two fields 00 to 99
*/
- if (l < 13) goto err;
- for (i=0; i<7; i++) {
+ if (l < 13)
+ goto err;
+ for (i = 0; i < 7; i++) {
if ((i == 6) && ((a[o] == 'Z') ||
- (a[o] == '+') || (a[o] == '-')))
- { i++; break; }
- if ((a[o] < '0') || (a[o] > '9')) goto err;
+ (a[o] == '+') || (a[o] == '-'))) {
+ i++;
+ break;
+ }
+ if ((a[o] < '0') || (a[o] > '9'))
+ goto err;
n= a[o]-'0';
- if (++o > l) goto err;
+ if (++o > l)
+ goto err;
- if ((a[o] < '0') || (a[o] > '9')) goto err;
- n=(n*10)+ a[o]-'0';
- if (++o > l) goto err;
+ if ((a[o] < '0') || (a[o] > '9'))
+ goto err;
+ n = (n * 10)+ a[o] - '0';
+ if (++o > l)
+ goto err;
- if ((n < min[i]) || (n > max[i])) goto err;
+ if ((n < min[i]) || (n > max[i]))
+ goto err;
}
/* Optional fractional seconds: decimal point followed by one
* or more digits.
*/
- if (a[o] == '.')
- {
- if (++o > l) goto err;
+ if (a[o] == '.') {
+ if (++o > l)
+ goto err;
i = o;
while ((a[o] >= '0') && (a[o] <= '9') && (o <= l))
o++;
/* Must have at least one digit after decimal point */
- if (i == o) goto err;
+ if (i == o)
+ goto err;
}
if (a[o] == 'Z')
o++;
else if ((a[o] == '+') || (a[o] == '-')) {
o++;
- if (o+4 > l) goto err;
- for (i=7; i<9; i++) {
- if ((a[o] < '0') || (a[o] > '9')) goto err;
- n= a[o]-'0';
+ if (o + 4 > l)
+ goto err;
+ for (i = 7; i < 9; i++) {
+ if ((a[o] < '0') || (a[o] > '9'))
+ goto err;
+ n = a[o] - '0';
o++;
- if ((a[o] < '0') || (a[o] > '9')) goto err;
- n=(n*10)+ a[o]-'0';
- if ((n < min[i]) || (n > max[i])) goto err;
+ if ((a[o] < '0') || (a[o] > '9'))
+ goto err;
+ n = (n * 10) + a[o] - '0';
+ if ((n < min[i]) || (n > max[i]))
+ goto err;
o++;
}
} else {
/* Missing time zone information. */
goto err;
}
- return(o == l);
+ return (o == l);
err:
- return(0);
+ return (0);
}
-int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
+int
+ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
{
ASN1_GENERALIZEDTIME t;
- t.type=V_ASN1_GENERALIZEDTIME;
- t.length=strlen(str);
- t.data=(unsigned char *)str;
+ t.type = V_ASN1_GENERALIZEDTIME;
+ t.length = strlen(str);
+ t.data = (unsigned char *)str;
if (ASN1_GENERALIZEDTIME_check(&t)) {
if (s != NULL) {
if (!ASN1_STRING_set((ASN1_STRING *)s,
- (unsigned char *)str,t.length))
+ (unsigned char *)str, t.length))
return 0;
- s->type=V_ASN1_GENERALIZEDTIME;
+ s->type = V_ASN1_GENERALIZEDTIME;
}
- return(1);
- }
- else
- return(0);
+ return (1);
+ } else
+ return (0);
}
-ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
- time_t t)
+ASN1_GENERALIZEDTIME *
+ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, time_t t)
{
- return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0);
+ return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0);
}
-ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
- time_t t, int offset_day, long offset_sec)
+ASN1_GENERALIZEDTIME *
+ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day,
+ long offset_sec)
{
char *p;
struct tm *ts;
struct tm data;
- size_t len = 20;
+ size_t len = 20;
if (s == NULL)
- s=M_ASN1_GENERALIZEDTIME_new();
+ s = M_ASN1_GENERALIZEDTIME_new();
if (s == NULL)
- return(NULL);
+ return (NULL);
- ts=OPENSSL_gmtime(&t, &data);
+ ts = OPENSSL_gmtime(&t, &data);
if (ts == NULL)
- return(NULL);
+ return (NULL);
- if (offset_day || offset_sec) {
+ if (offset_day || offset_sec) {
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
return NULL;
}
- p=(char *)s->data;
+ p = (char *)s->data;
if ((p == NULL) || ((size_t)s->length < len)) {
- p=malloc(len);
+ p = malloc(len);
if (p == NULL) {
ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
- ERR_R_MALLOC_FAILURE);
- return(NULL);
+ ERR_R_MALLOC_FAILURE);
+ return (NULL);
}
if (s->data != NULL)
free(s->data);
- s->data=(unsigned char *)p;
+ s->data = (unsigned char *)p;
}
- (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
- ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
- s->length=strlen(p);
- s->type=V_ASN1_GENERALIZEDTIME;
- return(s);
+ (void) snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900,
+ ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);
+ s->length = strlen(p);
+ s->type = V_ASN1_GENERALIZEDTIME;
+ return (s);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#ifndef NO_OLD_ASN1
#ifndef OPENSSL_NO_FP_API
-int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
+int
+ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
{
- BIO *b;
- int ret;
+ BIO *b;
+ int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL) {
- ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
- return(0);
+ if ((b = BIO_new(BIO_s_file())) == NULL) {
+ ASN1err(ASN1_F_ASN1_I2D_FP, ERR_R_BUF_LIB);
+ return (0);
}
- BIO_set_fp(b,out,BIO_NOCLOSE);
- ret=ASN1_i2d_bio(i2d,b,x);
- BIO_free(b);
- return(ret);
+ BIO_set_fp(b, out, BIO_NOCLOSE);
+ ret = ASN1_i2d_bio(i2d, b, x);
+ BIO_free(b);
+ return (ret);
}
#endif
-int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
+int
+ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
{
char *b;
unsigned char *p;
- int i,j=0,n,ret=1;
+ int i, j = 0, n, ret = 1;
- n=i2d(x,NULL);
- b=(char *)malloc(n);
+ n = i2d(x, NULL);
+ b = (char *)malloc(n);
if (b == NULL) {
- ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
- return(0);
+ ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
+ return (0);
}
- p=(unsigned char *)b;
- i2d(x,&p);
-
+ p = (unsigned char *)b;
+ i2d(x, &p);
+
for (;;) {
- i=BIO_write(out,&(b[j]),n);
- if (i == n) break;
+ i = BIO_write(out, &(b[j]), n);
+ if (i == n)
+ break;
if (i <= 0) {
- ret=0;
+ ret = 0;
break;
}
- j+=i;
- n-=i;
+ j += i;
+ n -= i;
}
free(b);
- return(ret);
+ return (ret);
}
#endif
#ifndef OPENSSL_NO_FP_API
-int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
+int
+ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
{
- BIO *b;
- int ret;
+ BIO *b;
+ int ret;
- if ((b=BIO_new(BIO_s_file())) == NULL) {
- ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB);
- return(0);
+ if ((b = BIO_new(BIO_s_file())) == NULL) {
+ ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB);
+ return (0);
}
- BIO_set_fp(b,out,BIO_NOCLOSE);
- ret=ASN1_item_i2d_bio(it,b,x);
- BIO_free(b);
- return(ret);
+ BIO_set_fp(b, out, BIO_NOCLOSE);
+ ret = ASN1_item_i2d_bio(it, b, x);
+ BIO_free(b);
+ return (ret);
}
#endif
-int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
+int
+ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
{
unsigned char *b = NULL;
- int i,j=0,n,ret=1;
+ int i, j = 0, n, ret = 1;
n = ASN1_item_i2d(x, &b, it);
if (b == NULL) {
- ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE);
- return(0);
+ ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO, ERR_R_MALLOC_FAILURE);
+ return (0);
}
for (;;) {
- i=BIO_write(out,&(b[j]),n);
- if (i == n) break;
+ i = BIO_write(out, &(b[j]), n);
+ if (i == n)
+ break;
if (i <= 0) {
- ret=0;
+ ret = 0;
break;
}
- j+=i;
- n-=i;
+ j += i;
+ n -= i;
}
free(b);
- return(ret);
+ return (ret);
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include <openssl/asn1.h>
#include <openssl/bn.h>
-ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x)
-{ return M_ASN1_INTEGER_dup(x);}
+ASN1_INTEGER *
+ASN1_INTEGER_dup(const ASN1_INTEGER *x)
+{
+ return M_ASN1_INTEGER_dup(x);
+}
-int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
-{
+int
+ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
+{
int neg, ret;
+
/* Compare signs */
neg = x->type & V_ASN1_NEG;
if (neg != (y->type & V_ASN1_NEG)) {
else
return ret;
}
-
-/*
+
+/*
* This converts an ASN1 INTEGER into its content encoding.
* The internal representation is an ASN1_STRING whose data is a big endian
* representation of the value, ignoring the sign. The sign is determined by
- * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
+ * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
*
* Positive integers are no problem: they are almost the same as the DER
* encoding, except if the first byte is >= 0x80 we need to add a zero pad.
*
* Negative integers are a bit trickier...
* The DER representation of negative integers is in 2s complement form.
- * The internal form is converted by complementing each octet and finally
+ * The internal form is converted by complementing each octet and finally
* adding one to the result. This can be done less messily with a little trick.
* If the internal form has trailing zeroes then they will become FF by the
- * complement and 0 by the add one (due to carry) so just copy as many trailing
+ * complement and 0 by the add one (due to carry) so just copy as many trailing
* zeros to the destination as there are in the source. The carry will add one
* to the last none zero octet: so complement this octet and add one and finally
* complement any left over until you get to the start of the string.
* followed by optional zeros isn't padded.
*/
-int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
+int
+i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
{
- int pad=0,ret,i,neg;
- unsigned char *p,*n,pb=0;
+ int pad = 0, ret, i, neg;
+ unsigned char *p, *n, pb = 0;
- if (a == NULL) return(0);
- neg=a->type & V_ASN1_NEG;
+ if (a == NULL)
+ return (0);
+ neg = a->type & V_ASN1_NEG;
if (a->length == 0)
- ret=1;
+ ret = 1;
else {
- ret=a->length;
- i=a->data[0];
+ ret = a->length;
+ i = a->data[0];
if (!neg && (i > 127)) {
- pad=1;
- pb=0;
- } else if(neg) {
- if(i>128) {
- pad=1;
- pb=0xFF;
- } else if(i == 128) {
- /*
- * Special case: if any other bytes non zero we pad:
- * otherwise we don't.
- */
- for(i = 1; i < a->length; i++) if(a->data[i]) {
- pad=1;
- pb=0xFF;
- break;
+ pad = 1;
+ pb = 0;
+ } else if (neg) {
+ if (i > 128) {
+ pad = 1;
+ pb = 0xFF;
+ } else if (i == 128) {
+ /*
+ * Special case: if any other bytes non zero we pad:
+ * otherwise we don't.
+ */
+ for (i = 1; i < a->length; i++) if (a->data[i]) {
+ pad = 1;
+ pb = 0xFF;
+ break;
+ }
}
}
+ ret += pad;
}
- ret+=pad;
- }
- if (pp == NULL) return(ret);
+ if (pp == NULL)
+ return (ret);
p= *pp;
- if (pad) *(p++)=pb;
- if (a->length == 0) *(p++)=0;
- else if (!neg) memcpy(p,a->data,(unsigned int)a->length);
+ if (pad)
+ *(p++) = pb;
+ if (a->length == 0)
+ *(p++) = 0;
+ else if (!neg)
+ memcpy(p, a->data, (unsigned int)a->length);
else {
/* Begin at the end of the encoding */
- n=a->data + a->length - 1;
+ n = a->data + a->length - 1;
p += a->length - 1;
i = a->length;
/* Copy zeros to destination as long as source is zero */
- while(!*n) {
+ while (!*n) {
*(p--) = 0;
n--;
i--;
- }
+ }
/* Complement and increment next octet */
*(p--) = ((*(n--)) ^ 0xff) + 1;
i--;
/* Complement any octets left */
- for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
-}
+ for(; i > 0; i--)
+ *(p--) = *(n--) ^ 0xff;
+ }
- *pp+=ret;
- return(ret);
+ *pp += ret;
+ return (ret);
}
/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
-ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
- long len)
+ASN1_INTEGER *
+c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
{
- ASN1_INTEGER *ret=NULL;
+ ASN1_INTEGER *ret = NULL;
const unsigned char *p, *pend;
- unsigned char *to,*s;
+ unsigned char *to, *s;
int i;
if ((a == NULL) || ((*a) == NULL)) {
- if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
- ret->type=V_ASN1_INTEGER;
- }
- else
- ret=(*a);
+ if ((ret = M_ASN1_INTEGER_new()) == NULL)
+ return (NULL);
+ ret->type = V_ASN1_INTEGER;
+ } else
+ ret = (*a);
p= *pp;
pend = p + len;
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
- s=(unsigned char *)malloc((int)len+1);
+ s = (unsigned char *)malloc((int)len + 1);
if (s == NULL) {
- i=ERR_R_MALLOC_FAILURE;
+ i = ERR_R_MALLOC_FAILURE;
goto err;
}
- to=s;
- if(!len) {
+ to = s;
+ if (!len) {
/* Strictly speaking this is an illegal INTEGER but we
* tolerate it.
*/
- ret->type=V_ASN1_INTEGER;
+ ret->type = V_ASN1_INTEGER;
} else if (*p & 0x80) /* a negative number */ {
- ret->type=V_ASN1_NEG_INTEGER;
+ ret->type = V_ASN1_NEG_INTEGER;
if ((*p == 0xff) && (len != 1)) {
p++;
len--;
* a 1. This is treated separately because it is the only case
* where the number of bytes is larger than len.
*/
- if(!i) {
+ if (!i) {
*s = 1;
s[len] = 0;
len++;
} else {
*(to--) = (*(p--) ^ 0xff) + 1;
i--;
- for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
+ for(; i > 0; i--)
+ *(to--) = *(p--) ^ 0xff;
}
} else {
- ret->type=V_ASN1_INTEGER;
+ ret->type = V_ASN1_INTEGER;
if ((*p == 0) && (len != 1)) {
p++;
len--;
}
- memcpy(s,p,(int)len);
+ memcpy(s, p, (int)len);
}
- if (ret->data != NULL) free(ret->data);
- ret->data=s;
- ret->length=(int)len;
- if (a != NULL) (*a)=ret;
- *pp=pend;
- return(ret);
+ if (ret->data != NULL)
+ free(ret->data);
+ ret->data = s;
+ ret->length = (int)len;
+ if (a != NULL)
+ (*a) = ret;
+ *pp = pend;
+ return (ret);
+
err:
- ASN1err(ASN1_F_C2I_ASN1_INTEGER,i);
+ ASN1err(ASN1_F_C2I_ASN1_INTEGER, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_INTEGER_free(ret);
- return(NULL);
+ return (NULL);
}
* with its MSB set as negative (it doesn't add a padding zero).
*/
-ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
- long length)
+ASN1_INTEGER *
+d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
{
- ASN1_INTEGER *ret=NULL;
+ ASN1_INTEGER *ret = NULL;
const unsigned char *p;
unsigned char *s;
long len;
- int inf,tag,xclass;
+ int inf, tag, xclass;
int i;
if ((a == NULL) || ((*a) == NULL)) {
- if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL);
- ret->type=V_ASN1_INTEGER;
+ if ((ret = M_ASN1_INTEGER_new()) == NULL)
+ return (NULL);
+ ret->type = V_ASN1_INTEGER;
} else
- ret=(*a);
+ ret = (*a);
- p= *pp;
- inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
+ p = *pp;
+ inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
- i=ASN1_R_BAD_OBJECT_HEADER;
+ i = ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
if (tag != V_ASN1_INTEGER) {
- i=ASN1_R_EXPECTING_AN_INTEGER;
+ i = ASN1_R_EXPECTING_AN_INTEGER;
goto err;
}
/* We must malloc stuff, even for 0 bytes otherwise it
* signifies a missing NULL parameter. */
- s=(unsigned char *)malloc((int)len+1);
+ s = (unsigned char *)malloc((int)len + 1);
if (s == NULL) {
- i=ERR_R_MALLOC_FAILURE;
+ i = ERR_R_MALLOC_FAILURE;
goto err;
}
- ret->type=V_ASN1_INTEGER;
- if(len) {
+ ret->type = V_ASN1_INTEGER;
+ if (len) {
if ((*p == 0) && (len != 1)) {
p++;
len--;
}
- memcpy(s,p,(int)len);
- p+=len;
+ memcpy(s, p, (int)len);
+ p += len;
}
- if (ret->data != NULL) free(ret->data);
- ret->data=s;
- ret->length=(int)len;
- if (a != NULL) (*a)=ret;
- *pp=p;
- return(ret);
+ if (ret->data != NULL)
+ free(ret->data);
+ ret->data = s;
+ ret->length = (int)len;
+ if (a != NULL)
+ (*a) = ret;
+ *pp = p;
+ return (ret);
+
err:
- ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
+ ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
M_ASN1_INTEGER_free(ret);
- return(NULL);
+ return (NULL);
}
-int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
+int
+ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
{
- int j,k;
+ int j, k;
unsigned int i;
- unsigned char buf[sizeof(long)+1];
+ unsigned char buf[sizeof(long) + 1];
long d;
- a->type=V_ASN1_INTEGER;
- if (a->length < (int)(sizeof(long)+1)) {
+ a->type = V_ASN1_INTEGER;
+ if (a->length < (int)(sizeof(long) + 1)) {
if (a->data != NULL)
free(a->data);
- if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
- memset((char *)a->data,0,sizeof(long)+1);
+ if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
+ memset((char *)a->data, 0, sizeof(long) + 1);
}
if (a->data == NULL) {
- ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
- return(0);
+ ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE);
+ return (0);
}
- d=v;
+ d = v;
if (d < 0) {
- d= -d;
- a->type=V_ASN1_NEG_INTEGER;
+ d = -d;
+ a->type = V_ASN1_NEG_INTEGER;
}
- for (i=0; i<sizeof(long); i++) {
- if (d == 0) break;
- buf[i]=(int)d&0xff;
- d>>=8;
+ for (i = 0; i < sizeof(long); i++) {
+ if (d == 0)
+ break;
+ buf[i] = (int)d & 0xff;
+ d >>= 8;
}
- j=0;
- for (k=i-1; k >=0; k--)
- a->data[j++]=buf[k];
- a->length=j;
- return(1);
+ j = 0;
+ for (k = i - 1; k >= 0; k--)
+ a->data[j++] = buf[k];
+ a->length = j;
+ return (1);
}
-long ASN1_INTEGER_get(const ASN1_INTEGER *a)
+long
+ASN1_INTEGER_get(const ASN1_INTEGER *a)
{
- int neg=0,i;
- long r=0;
+ int neg = 0, i;
+ long r = 0;
- if (a == NULL) return(0L);
- i=a->type;
+ if (a == NULL)
+ return (0L);
+ i = a->type;
if (i == V_ASN1_NEG_INTEGER)
- neg=1;
+ neg = 1;
else if (i != V_ASN1_INTEGER)
return -1;
-
+
if (a->length > (int)sizeof(long)) {
/* hmm... a bit ugly, return all ones */
return -1;
if (a->data == NULL)
return 0;
- for (i=0; i<a->length; i++) {
- r<<=8;
- r|=(unsigned char)a->data[i];
+ for (i = 0; i < a->length; i++) {
+ r <<= 8;
+ r |= (unsigned char)a->data[i];
}
- if (neg) r= -r;
- return(r);
+ if (neg)
+ r = -r;
+ return (r);
}
-ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
+ASN1_INTEGER *
+BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
{
ASN1_INTEGER *ret;
- int len,j;
+ int len, j;
if (ai == NULL)
- ret=M_ASN1_INTEGER_new();
+ ret = M_ASN1_INTEGER_new();
else
- ret=ai;
+ ret = ai;
if (ret == NULL) {
- ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
+ ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (BN_is_negative(bn))
ret->type = V_ASN1_NEG_INTEGER;
- else ret->type=V_ASN1_INTEGER;
- j=BN_num_bits(bn);
- len=((j == 0)?0:((j/8)+1));
- if (ret->length < len+4) {
- unsigned char *new_data=realloc(ret->data, len+4);
+ else
+ ret->type = V_ASN1_INTEGER;
+ j = BN_num_bits(bn);
+ len = ((j == 0) ? 0 : ((j / 8) + 1));
+ if (ret->length < len + 4) {
+ unsigned char *new_data = realloc(ret->data, len + 4);
if (!new_data) {
- ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
+ ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
goto err;
}
- ret->data=new_data;
+ ret->data = new_data;
}
- ret->length=BN_bn2bin(bn,ret->data);
+ ret->length = BN_bn2bin(bn, ret->data);
+
/* Correct zero case */
- if(!ret->length) {
+ if (!ret->length) {
ret->data[0] = 0;
ret->length = 1;
}
- return(ret);
+ return (ret);
+
err:
- if (ret != ai) M_ASN1_INTEGER_free(ret);
- return(NULL);
+ if (ret != ai)
+ M_ASN1_INTEGER_free(ret);
+ return (NULL);
}
-BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
+BIGNUM *
+ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
{
BIGNUM *ret;
- if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
- ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
- else if(ai->type == V_ASN1_NEG_INTEGER)
+ if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
+ ASN1err(ASN1_F_ASN1_INTEGER_TO_BN, ASN1_R_BN_LIB);
+ else if (ai->type == V_ASN1_NEG_INTEGER)
BN_set_negative(ret, 1);
- return(ret);
+ return (ret);
}
IMPLEMENT_STACK_OF(ASN1_INTEGER)
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
#include <openssl/asn1.h>
static int traverse_string(const unsigned char *p, int len, int inform,
- int (*rfunc)(unsigned long value, void *in), void *arg);
+ int (*rfunc)(unsigned long value, void *in), void *arg);
static int in_utf8(unsigned long value, void *arg);
static int out_utf8(unsigned long value, void *arg);
static int type_str(unsigned long value, void *arg);
* The 'ncopy' form checks minimum and maximum size limits too.
*/
-int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
- int inform, unsigned long mask)
+int
+ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
+ int inform, unsigned long mask)
{
return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
}
-int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
- int inform, unsigned long mask,
- long minsize, long maxsize)
+int
+ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
+ int inform, unsigned long mask,
+ long minsize, long maxsize)
{
int str_type;
int ret;
unsigned char *p;
int nchar;
char strbuf[32];
- int (*cpyfunc)(unsigned long,void *) = NULL;
- if(len == -1) len = strlen((const char *)in);
- if(!mask) mask = DIRSTRING_TYPE;
+ int (*cpyfunc)(unsigned long, void *) = NULL;
+
+ if (len == -1)
+ len = strlen((const char *)in);
+ if (!mask)
+ mask = DIRSTRING_TYPE;
/* First do a string check and work out the number of characters */
- switch(inform) {
+ switch (inform) {
- case MBSTRING_BMP:
- if(len & 1) {
+ case MBSTRING_BMP:
+ if (len & 1) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
- ASN1_R_INVALID_BMPSTRING_LENGTH);
+ ASN1_R_INVALID_BMPSTRING_LENGTH);
return -1;
}
nchar = len >> 1;
break;
- case MBSTRING_UNIV:
- if(len & 3) {
+ case MBSTRING_UNIV:
+ if (len & 3) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
- ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
+ ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
return -1;
}
nchar = len >> 2;
break;
- case MBSTRING_UTF8:
+ case MBSTRING_UTF8:
nchar = 0;
/* This counts the characters and does utf8 syntax checking */
ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
- if(ret < 0) {
+ if (ret < 0) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
- ASN1_R_INVALID_UTF8STRING);
+ ASN1_R_INVALID_UTF8STRING);
return -1;
}
break;
- case MBSTRING_ASC:
+ case MBSTRING_ASC:
nchar = len;
break;
- default:
+ default:
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT);
return -1;
}
- if((minsize > 0) && (nchar < minsize)) {
+ if ((minsize > 0) && (nchar < minsize)) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT);
(void) snprintf(strbuf, sizeof strbuf, "%ld", minsize);
ERR_add_error_data(2, "minsize=", strbuf);
return -1;
}
- if((maxsize > 0) && (nchar > maxsize)) {
+ if ((maxsize > 0) && (nchar > maxsize)) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG);
(void) snprintf(strbuf, sizeof strbuf, "%ld", maxsize);
ERR_add_error_data(2, "maxsize=", strbuf);
}
/* Now work out minimal type (if any) */
- if(traverse_string(in, len, inform, type_str, &mask) < 0) {
+ if (traverse_string(in, len, inform, type_str, &mask) < 0) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS);
return -1;
}
/* Now work out output format and string type */
outform = MBSTRING_ASC;
- if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING;
- else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING;
- else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING;
- else if(mask & B_ASN1_BMPSTRING) {
+ if (mask & B_ASN1_PRINTABLESTRING)
+ str_type = V_ASN1_PRINTABLESTRING;
+ else if (mask & B_ASN1_IA5STRING)
+ str_type = V_ASN1_IA5STRING;
+ else if (mask & B_ASN1_T61STRING)
+ str_type = V_ASN1_T61STRING;
+ else if (mask & B_ASN1_BMPSTRING) {
str_type = V_ASN1_BMPSTRING;
outform = MBSTRING_BMP;
- } else if(mask & B_ASN1_UNIVERSALSTRING) {
+ } else if (mask & B_ASN1_UNIVERSALSTRING) {
str_type = V_ASN1_UNIVERSALSTRING;
outform = MBSTRING_UNIV;
} else {
str_type = V_ASN1_UTF8STRING;
outform = MBSTRING_UTF8;
}
- if(!out) return str_type;
- if(*out) {
+ if (!out)
+ return str_type;
+ if (*out) {
free_out = 0;
dest = *out;
- if(dest->data) {
+ if (dest->data) {
dest->length = 0;
free(dest->data);
dest->data = NULL;
} else {
free_out = 1;
dest = ASN1_STRING_type_new(str_type);
- if(!dest) {
+ if (!dest) {
ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
- ERR_R_MALLOC_FAILURE);
+ ERR_R_MALLOC_FAILURE);
return -1;
}
*out = dest;
}
/* If both the same type just copy across */
- if(inform == outform) {
- if(!ASN1_STRING_set(dest, in, len)) {
- ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE);
+ if (inform == outform) {
+ if (!ASN1_STRING_set(dest, in, len)) {
+ ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,
+ ERR_R_MALLOC_FAILURE);
return -1;
}
return str_type;
- }
+ }
/* Work out how much space the destination will need */
- switch(outform) {
- case MBSTRING_ASC:
+ switch (outform) {
+ case MBSTRING_ASC:
outlen = nchar;
cpyfunc = cpy_asc;
break;
- case MBSTRING_BMP:
+ case MBSTRING_BMP:
outlen = nchar << 1;
cpyfunc = cpy_bmp;
break;
- case MBSTRING_UNIV:
+ case MBSTRING_UNIV:
outlen = nchar << 2;
cpyfunc = cpy_univ;
break;
- case MBSTRING_UTF8:
+ case MBSTRING_UTF8:
outlen = 0;
traverse_string(in, len, inform, out_utf8, &outlen);
cpyfunc = cpy_utf8;
break;
}
- if(!(p = malloc(outlen + 1))) {
- if(free_out) ASN1_STRING_free(dest);
- ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE);
+ if (!(p = malloc(outlen + 1))) {
+ if (free_out)
+ ASN1_STRING_free(dest);
+ ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE);
return -1;
}
dest->length = outlen;
dest->data = p;
p[outlen] = 0;
traverse_string(in, len, inform, cpyfunc, &p);
- return str_type;
+ return str_type;
}
/* This function traverses a string and passes the value of each character
* to an optional function along with a void * argument.
*/
-static int traverse_string(const unsigned char *p, int len, int inform,
- int (*rfunc)(unsigned long value, void *in), void *arg)
+static int
+traverse_string(const unsigned char *p, int len, int inform,
+ int (*rfunc)(unsigned long value, void *in), void *arg)
{
unsigned long value;
int ret;
- while(len) {
- if(inform == MBSTRING_ASC) {
+ while (len) {
+ if (inform == MBSTRING_ASC) {
value = *p++;
len--;
- } else if(inform == MBSTRING_BMP) {
+ } else if (inform == MBSTRING_BMP) {
value = *p++ << 8;
value |= *p++;
len -= 2;
- } else if(inform == MBSTRING_UNIV) {
+ } else if (inform == MBSTRING_UNIV) {
value = ((unsigned long)*p++) << 24;
value |= ((unsigned long)*p++) << 16;
value |= *p++ << 8;
len -= 4;
} else {
ret = UTF8_getc(p, len, &value);
- if(ret < 0) return -1;
- len -= ret;
+ if (ret < 0) return -1;
+ len -= ret;
p += ret;
}
- if(rfunc) {
+ if (rfunc) {
ret = rfunc(value, arg);
- if(ret <= 0) return ret;
+ if (ret <= 0)
+ return ret;
}
}
return 1;
/* Just count number of characters */
-static int in_utf8(unsigned long value, void *arg)
+static int
+in_utf8(unsigned long value, void *arg)
{
int *nchar;
nchar = arg;
/* Determine size of output as a UTF8 String */
-static int out_utf8(unsigned long value, void *arg)
+static int
+out_utf8(unsigned long value, void *arg)
{
int *outlen;
outlen = arg;
* supplied "mask".
*/
-static int type_str(unsigned long value, void *arg)
+static int
+type_str(unsigned long value, void *arg)
{
unsigned long types;
+
types = *((unsigned long *)arg);
- if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
- types &= ~B_ASN1_PRINTABLESTRING;
- if((types & B_ASN1_IA5STRING) && (value > 127))
- types &= ~B_ASN1_IA5STRING;
- if((types & B_ASN1_T61STRING) && (value > 0xff))
- types &= ~B_ASN1_T61STRING;
- if((types & B_ASN1_BMPSTRING) && (value > 0xffff))
- types &= ~B_ASN1_BMPSTRING;
- if(!types) return -1;
+ if ((types & B_ASN1_PRINTABLESTRING) && !is_printable(value))
+ types &= ~B_ASN1_PRINTABLESTRING;
+ if ((types & B_ASN1_IA5STRING) && (value > 127))
+ types &= ~B_ASN1_IA5STRING;
+ if ((types & B_ASN1_T61STRING) && (value > 0xff))
+ types &= ~B_ASN1_T61STRING;
+ if ((types & B_ASN1_BMPSTRING) && (value > 0xffff))
+ types &= ~B_ASN1_BMPSTRING;
+ if (!types)
+ return -1;
*((unsigned long *)arg) = types;
return 1;
}
/* Copy one byte per character ASCII like strings */
-static int cpy_asc(unsigned long value, void *arg)
+static int
+cpy_asc(unsigned long value, void *arg)
{
unsigned char **p, *q;
+
p = arg;
q = *p;
*q = (unsigned char) value;
/* Copy two byte per character BMPStrings */
-static int cpy_bmp(unsigned long value, void *arg)
+static int
+cpy_bmp(unsigned long value, void *arg)
{
unsigned char **p, *q;
+
p = arg;
q = *p;
*q++ = (unsigned char) ((value >> 8) & 0xff);
/* Copy four byte per character UniversalStrings */
-static int cpy_univ(unsigned long value, void *arg)
+static int
+cpy_univ(unsigned long value, void *arg)
{
unsigned char **p, *q;
+
p = arg;
q = *p;
*q++ = (unsigned char) ((value >> 24) & 0xff);
/* Copy to a UTF8String */
-static int cpy_utf8(unsigned long value, void *arg)
+static int
+cpy_utf8(unsigned long value, void *arg)
{
unsigned char **p;
+
int ret;
p = arg;
/* We already know there is enough room so pass 0xff as the length */
}
/* Return 1 if the character is permitted in a PrintableString */
-static int is_printable(unsigned long value)
+static int
+is_printable(unsigned long value)
{
int ch;
- if(value > 0x7f) return 0;
- ch = (int) value;
- /* Note: we can't use 'isalnum' because certain accented
+
+ if (value > 0x7f) return 0;
+ ch = (int)value;
+ /* Note: we can't use 'isalnum' because certain accented
* characters may count as alphanumeric in some environments.
*/
- if((ch >= 'a') && (ch <= 'z')) return 1;
- if((ch >= 'A') && (ch <= 'Z')) return 1;
- if((ch >= '0') && (ch <= '9')) return 1;
- if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
+ if ((ch >= 'a') && (ch <= 'z'))
+ return 1;
+ if ((ch >= 'A') && (ch <= 'Z'))
+ return 1;
+ if ((ch >= '0') && (ch <= '9'))
+ return 1;
+ if ((ch == ' ') || strchr("'()+,-./:=?", ch))
+ return 1;
return 0;
}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include <openssl/objects.h>
#include <openssl/bn.h>
-int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
+int
+i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
{
unsigned char *p;
int objsize;
- if ((a == NULL) || (a->data == NULL)) return(0);
+ if ((a == NULL) || (a->data == NULL))
+ return (0);
- objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT);
- if (pp == NULL) return objsize;
+ objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
+ if (pp == NULL)
+ return objsize;
- p= *pp;
- ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
- memcpy(p,a->data,a->length);
- p+=a->length;
+ p = *pp;
+ ASN1_put_object(&p, 0,a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL);
+ memcpy(p, a->data, a->length);
+ p += a->length;
- *pp=p;
- return(objsize);
+ *pp = p;
+ return (objsize);
}
-int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
+int
+a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
{
- int i,first,len=0,c, use_bn;
+ int i, first, len = 0, c, use_bn;
char ftmp[24], *tmp = ftmp;
int tmpsize = sizeof ftmp;
const char *p;
BIGNUM *bl = NULL;
if (num == 0)
- return(0);
+ return (0);
else if (num == -1)
- num=strlen(buf);
+ num = strlen(buf);
- p=buf;
- c= *(p++);
+ p = buf;
+ c = *(p++);
num--;
if ((c >= '0') && (c <= '2')) {
first= c-'0';
} else {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE);
goto err;
}
if (num <= 0) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER);
goto err;
}
- c= *(p++);
+ c = *(p++);
num--;
for (;;) {
- if (num <= 0) break;
+ if (num <= 0)
+ break;
if ((c != '.') && (c != ' ')) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT,
+ ASN1_R_INVALID_SEPARATOR);
goto err;
}
- l=0;
+ l = 0;
use_bn = 0;
for (;;) {
- if (num <= 0) break;
+ if (num <= 0)
+ break;
num--;
- c= *(p++);
+ c = *(p++);
if ((c == ' ') || (c == '.'))
break;
if ((c < '0') || (c > '9')) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT,
+ ASN1_R_INVALID_DIGIT);
goto err;
}
if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
goto err;
}
if (use_bn) {
- if (!BN_mul_word(bl, 10L)
- || !BN_add_word(bl, c-'0'))
+ if (!BN_mul_word(bl, 10L) ||
+ !BN_add_word(bl, c-'0'))
goto err;
- }
- else
- l=l*10L+(long)(c-'0');
+ } else
+ l = l * 10L + (long)(c - '0');
}
if (len == 0) {
if ((first < 2) && (l >= 40)) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT,
+ ASN1_R_SECOND_NUMBER_TOO_LARGE);
goto err;
}
if (use_bn) {
if (!BN_add_word(bl, first * 40))
goto err;
- }
- else
- l+=(long)first*40;
+ } else
+ l += (long)first * 40;
}
- i=0;
+ i = 0;
if (use_bn) {
int blsize;
blsize = BN_num_bits(bl);
- blsize = (blsize + 6)/7;
+ blsize = (blsize + 6) / 7;
if (blsize > tmpsize) {
if (tmp != ftmp)
free(tmp);
if (!tmp)
goto err;
}
- while(blsize--)
+ while (blsize--)
tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L);
} else {
-
+
for (;;) {
- tmp[i++]=(unsigned char)l&0x7f;
- l>>=7L;
- if (l == 0L) break;
+ tmp[i++] = (unsigned char)l & 0x7f;
+ l >>= 7L;
+ if (l == 0L)
+ break;
}
}
if (out != NULL) {
- if (len+i > olen) {
- ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL);
+ if (len + i > olen) {
+ ASN1err(ASN1_F_A2D_ASN1_OBJECT,
+ ASN1_R_BUFFER_TOO_SMALL);
goto err;
}
while (--i > 0)
- out[len++]=tmp[i]|0x80;
- out[len++]=tmp[0];
- }
- else
- len+=i;
+ out[len++] = tmp[i]|0x80;
+ out[len++] = tmp[0];
+ } else
+ len += i;
}
if (tmp != ftmp)
free(tmp);
if (bl)
BN_free(bl);
- return(len);
+ return (len);
+
err:
if (tmp != ftmp)
free(tmp);
if (bl)
BN_free(bl);
- return(0);
+ return (0);
}
-int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
+int
+i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
{
return OBJ_obj2txt(buf, buf_len, a, 0);
}
-int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
+int
+i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
{
char buf[80], *p = buf;
int i;
if ((a == NULL) || (a->data == NULL))
- return(BIO_write(bp,"NULL",4));
- i=i2t_ASN1_OBJECT(buf,sizeof buf,a);
+ return(BIO_write(bp, "NULL",4));
+ i = i2t_ASN1_OBJECT(buf, sizeof buf, a);
if (i > (int)(sizeof(buf) - 1)) {
p = malloc(i + 1);
if (!p)
return -1;
- i2t_ASN1_OBJECT(p,i + 1,a);
+ i2t_ASN1_OBJECT(p, i + 1, a);
}
if (i <= 0)
return BIO_write(bp, "<INVALID>", 9);
- BIO_write(bp,p,i);
+ BIO_write(bp, p, i);
if (p != buf)
free(p);
- return(i);
+ return (i);
}
-ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
- long length)
+ASN1_OBJECT *
+d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length)
{
const unsigned char *p;
long len;
- int tag,xclass;
- int inf,i;
+ int tag, xclass;
+ int inf, i;
ASN1_OBJECT *ret = NULL;
- p= *pp;
- inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
+
+ p = *pp;
+ inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
- i=ASN1_R_BAD_OBJECT_HEADER;
+ i = ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
if (tag != V_ASN1_OBJECT) {
- i=ASN1_R_EXPECTING_AN_OBJECT;
+ i = ASN1_R_EXPECTING_AN_OBJECT;
goto err;
}
ret = c2i_ASN1_OBJECT(a, &p, len);
- if(ret) *pp = p;
+ if (ret)
+ *pp = p;
return ret;
+
err:
- ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
- return(NULL);
+ ASN1err(ASN1_F_D2I_ASN1_OBJECT, i);
+ return (NULL);
}
-ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
- long len)
+
+ASN1_OBJECT *
+c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
{
- ASN1_OBJECT *ret=NULL;
+ ASN1_OBJECT *ret = NULL;
const unsigned char *p;
unsigned char *data;
int i;
+
/* Sanity check OID encoding: can't have leading 0x80 in
* subidentifiers, see: X.690 8.19.2
*/
for (i = 0, p = *pp; i < len; i++, p++) {
if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
- ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING);
+ ASN1err(ASN1_F_C2I_ASN1_OBJECT,
+ ASN1_R_INVALID_OBJECT_ENCODING);
return NULL;
}
}
/* only the ASN1_OBJECTs from the 'table' will have values
* for ->sn or ->ln */
if ((a == NULL) || ((*a) == NULL) ||
- !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
- if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL);
- }
- else ret=(*a);
+ !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
+ if ((ret = ASN1_OBJECT_new()) == NULL)
+ return (NULL);
+ } else
+ ret = (*a);
- p= *pp;
+ p = *pp;
/* detach data from object */
data = (unsigned char *)ret->data;
ret->data = NULL;
/* once detached we can change it */
if ((data == NULL) || (ret->length < len)) {
- ret->length=0;
- if (data != NULL) free(data);
- data=(unsigned char *)malloc(len ? (int)len : 1);
- if (data == NULL) { i=ERR_R_MALLOC_FAILURE; goto err; }
- ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
+ ret->length = 0;
+ if (data != NULL)
+ free(data);
+ data = (unsigned char *)malloc(len ? (int)len : 1);
+ if (data == NULL) {
+ i = ERR_R_MALLOC_FAILURE;
+ goto err;
+ }
+ ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
}
- memcpy(data,p,(int)len);
+ memcpy(data, p, (int)len);
/* reattach data to object, after which it remains const */
- ret->data =data;
- ret->length=(int)len;
- ret->sn=NULL;
- ret->ln=NULL;
+ ret->data = data;
+ ret->length = (int)len;
+ ret->sn = NULL;
+ ret->ln = NULL;
/* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
- p+=len;
+ p += len;
+
+ if (a != NULL)
+ (*a) = ret;
+ *pp = p;
+ return (ret);
- if (a != NULL) (*a)=ret;
- *pp=p;
- return(ret);
err:
- ASN1err(ASN1_F_C2I_ASN1_OBJECT,i);
+ ASN1err(ASN1_F_C2I_ASN1_OBJECT, i);
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
ASN1_OBJECT_free(ret);
- return(NULL);
+ return (NULL);
}
-ASN1_OBJECT *ASN1_OBJECT_new(void)
+ASN1_OBJECT *
+ASN1_OBJECT_new(void)
{
ASN1_OBJECT *ret;
- ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
+ ret = (ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
if (ret == NULL) {
- ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
- return(NULL);
+ ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
+ return (NULL);
}
- ret->length=0;
- ret->data=NULL;
- ret->nid=0;
- ret->sn=NULL;
- ret->ln=NULL;
- ret->flags=ASN1_OBJECT_FLAG_DYNAMIC;
- return(ret);
+ ret->length = 0;
+ ret->data = NULL;
+ ret->nid = 0;
+ ret->sn = NULL;
+ ret->ln = NULL;
+ ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
+ return (ret);
}
-void ASN1_OBJECT_free(ASN1_OBJECT *a)
+void
+ASN1_OBJECT_free(ASN1_OBJECT *a)
{
- if (a == NULL) return;
+ if (a == NULL)
+ return;
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
- if (a->sn != NULL) free((void *)a->sn);
- if (a->ln != NULL) free((void *)a->ln);
+ if (a->sn != NULL)
+ free((void *)a->sn);
+ if (a->ln != NULL)
+ free((void *)a->ln);
#endif
- a->sn=a->ln=NULL;
+ a->sn = a->ln = NULL;
}
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
- if (a->data != NULL) free((void *)a->data);
- a->data=NULL;
- a->length=0;
+ if (a->data != NULL)
+ free((void *)a->data);
+ a->data = NULL;
+ a->length = 0;
}
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
free(a);
}
-ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
- const char *sn, const char *ln)
+ASN1_OBJECT *
+ASN1_OBJECT_create(int nid, unsigned char *data, int len,
+ const char *sn, const char *ln)
{
ASN1_OBJECT o;
- o.sn=sn;
- o.ln=ln;
- o.data=data;
- o.nid=nid;
- o.length=len;
- o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
- ASN1_OBJECT_FLAG_DYNAMIC_DATA;
- return(OBJ_dup(&o));
+ o.sn = sn;
+ o.ln = ln;
+ o.data = data;
+ o.nid = nid;
+ o.length = len;
+ o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
+ ASN1_OBJECT_FLAG_DYNAMIC_DATA;
+ return (OBJ_dup(&o));
}
IMPLEMENT_STACK_OF(ASN1_OBJECT)
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include "cryptlib.h"
#include <openssl/asn1.h>
-ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
-{ return M_ASN1_OCTET_STRING_dup(x); }
-
-int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b)
-{ return M_ASN1_OCTET_STRING_cmp(a, b); }
+ASN1_OCTET_STRING *
+ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x)
+{
+ return M_ASN1_OCTET_STRING_dup(x);
+}
-int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
-{ return M_ASN1_OCTET_STRING_set(x, d, len); }
+int
+ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b)
+{
+ return M_ASN1_OCTET_STRING_cmp(a, b);
+}
+int
+ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
+{
+ return M_ASN1_OCTET_STRING_set(x, d, len);
+}
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
- *
+ *
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
+ *
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
+ * 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
+ *
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
+ *
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
#include "cryptlib.h"
#include <openssl/asn1.h>
-int ASN1_PRINTABLE_type(const unsigned char *s, int len)
+int
+ASN1_PRINTABLE_type(const unsigned char *s, int len)
{
int c;
- int ia5=0;
- int t61=0;
+ int ia5 = 0;
+ int t61 = 0;
- if (len <= 0) len= -1;
- if (s == NULL) return(V_ASN1_PRINTABLESTRING);
+ if (len <= 0)
+ len = -1;
+ if (s == NULL)
+ return (V_ASN1_PRINTABLESTRING);
while ((*s) && (len-- != 0)) {
c= *(s++);
- if (!( ((c >= 'a') && (c <= 'z')) ||
- ((c >= 'A') && (c <= 'Z')) ||
- (c == ' ') ||
- ((c >= '0') && (c <= '9')) ||
- (c == ' ') || (c == '\'') ||
- (c == '(') || (c == ')') ||
- (c == '+') || (c == ',') ||
- (c == '-') || (c == '.') ||
- (c == '/') || (c == ':') ||
- (c == '=') || (c == '?')))
- ia5=1;
- if (c&0x80)
- t61=1;
+ if (!(((c >= 'a') && (c <= 'z')) ||
+ ((c >= 'A') && (c <= 'Z')) ||
+ (c == ' ') ||
+ ((c >= '0') && (c <= '9')) ||
+ (c == ' ') || (c == '\'') ||
+ (c == '(') || (c == ')') ||
+ (c == '+') || (c == ',') ||
+ (c == '-') || (c == '.') ||
+ (c == '/') || (c == ':') ||
+ (c == '=') || (c == '?')))
+ ia5 = 1;
+ if (c & 0x80)
+ t61 = 1;
}
- if (t61) return(V_ASN1_T61STRING);
- if (ia5) return(V_ASN1_IA5STRING);
- return(V_ASN1_PRINTABLESTRING);
+ if (t61)
+ return (V_ASN1_T61STRING);
+ if (ia5)
+ return (V_ASN1_IA5STRING);
+ return (V_ASN1_PRINTABLESTRING);
}
-int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
+int
+ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
{
int i;
unsigned char *p;
- if (s->type != V_ASN1_UNIVERSALSTRING) return(0);
- if ((s->length%4) != 0) return(0);
- p=s->data;
- for (i=0; i<s->length; i+=4) {
+ if (s->type != V_ASN1_UNIVERSALSTRING)
+ return (0);
+ if ((s->length % 4) != 0)
+ return (0);
+ p = s->data;
+ for (i = 0; i < s->length; i += 4) {
if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0'))
break;
else
- p+=4;
+ p += 4;
}
- if (i < s->length) return(0);
- p=s->data;
- for (i=3; i<s->length; i+=4) {
- *(p++)=s->data[i];
+ if (i < s->length)
+ return (0);
+ p = s->data;
+ for (i = 3; i < s->length; i += 4) {
+ *(p++) = s->data[i];
}
- *(p)='\0';
- s->length/=4;
- s->type=ASN1_PRINTABLE_type(s->data,s->length);
- return(1);
+ *(p) = '\0';
+ s->length /= 4;
+ s->type = ASN1_PRINTABLE_type(s->data, s->length);
+ return (1);
}