summaryrefslogtreecommitdiffstats
path: root/crypto/asn1/a_int.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2015-05-19 17:02:29 +0100
committerDr. Stephen Henson <steve@openssl.org>2015-05-20 15:04:19 +0100
commitc5f2810581380bc248279207a4c58a126047acd8 (patch)
tree13b1e96391f89ddfddeae8c8e3792fe7dbf4507c /crypto/asn1/a_int.c
parentde57d2372985d2640ae82f7954bf9dc07caf2f09 (diff)
Add functions to convert between uint64_t and ASN1_INTEGER.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/asn1/a_int.c')
-rw-r--r--crypto/asn1/a_int.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/crypto/asn1/a_int.c b/crypto/asn1/a_int.c
index f3a7e6af63..9a58378b8a 100644
--- a/crypto/asn1/a_int.c
+++ b/crypto/asn1/a_int.c
@@ -58,6 +58,7 @@
#include <stdio.h>
#include "internal/cryptlib.h"
+#include "internal/numbers.h"
#include <limits.h>
#include <openssl/asn1.h>
#include <openssl/bn.h>
@@ -418,6 +419,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 +590,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);