Remove /* foo.c */ comments
[oweals/openssl.git] / crypto / asn1 / a_int.c
index f3a7e6af63305b90bb212f0a50360b0325a81337..af52beb420db071b1cdd4ee5a246ad90b7cb0fc5 100644 (file)
@@ -1,4 +1,3 @@
-/* crypto/asn1/a_int.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -58,6 +57,7 @@
 
 #include <stdio.h>
 #include "internal/cryptlib.h"
+#include "internal/numbers.h"
 #include <limits.h>
 #include <openssl/asn1.h>
 #include <openssl/bn.h>
@@ -157,8 +157,8 @@ static size_t i2c_ibuf(const unsigned char *b, size_t blen, int neg,
 
     if (pad)
         *(p++) = pb;
-    if (blen == 0)
-        *(p++) = 0;
+    if (b == NULL || blen == 0)
+        *p = 0;
     else if (!neg)
         memcpy(p, b, blen);
     else {
@@ -337,7 +337,7 @@ static int asn1_get_int64(int64_t *pr, const unsigned char *b, size_t blen,
             ASN1err(ASN1_F_ASN1_GET_INT64, ASN1_R_TOO_SMALL);
             return 0;
         }
-        *pr = (int64_t)-r;
+        *pr = -(int64_t)r;
     } else {
         if (r > INT64_MAX) {
             ASN1err(ASN1_F_ASN1_GET_INT64, ASN1_R_TOO_LARGE);
@@ -418,6 +418,35 @@ static int asn1_string_set_int64(ASN1_STRING *a, int64_t r, int itype)
     return ASN1_STRING_set(a, tbuf, l);
 }
 
+static int asn1_string_get_uint64(uint64_t *pr, const ASN1_STRING *a,
+                                  int itype)
+{
+    if (a == NULL) {
+        ASN1err(ASN1_F_ASN1_STRING_GET_UINT64, ERR_R_PASSED_NULL_PARAMETER);
+        return 0;
+    }
+    if ((a->type & ~V_ASN1_NEG) != itype) {
+        ASN1err(ASN1_F_ASN1_STRING_GET_UINT64, ASN1_R_WRONG_INTEGER_TYPE);
+        return 0;
+    }
+    if (a->type & V_ASN1_NEG) {
+        ASN1err(ASN1_F_ASN1_STRING_GET_UINT64, ASN1_R_ILLEGAL_NEGATIVE_VALUE);
+        return 0;
+    }
+    return asn1_get_uint64(pr, a->data, a->length);
+}
+
+static int asn1_string_set_uint64(ASN1_STRING *a, uint64_t r, int itype)
+{
+    unsigned char tbuf[sizeof(r)];
+    size_t l;
+    a->type = itype;
+    l = asn1_put_uint64(tbuf, r);
+    if (l == 0)
+        return 0;
+    return ASN1_STRING_set(a, tbuf, l);
+}
+
 /*
  * This is a version of d2i_ASN1_INTEGER that ignores the sign bit of ASN1
  * integers: some broken software can encode a positive INTEGER with its MSB
@@ -560,6 +589,16 @@ int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r)
     return asn1_string_set_int64(a, r, V_ASN1_INTEGER);
 }
 
+int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a)
+{
+    return asn1_string_get_uint64(pr, a, V_ASN1_INTEGER);
+}
+
+int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r)
+{
+    return asn1_string_set_uint64(a, r, V_ASN1_INTEGER);
+}
+
 int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
 {
     return ASN1_INTEGER_set_int64(a, v);