diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2022-01-08 21:36:40 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2022-01-08 21:36:40 +0000 |
commit | 8aeae2ca2fe381901950bbd49bdb3ead3b4467a2 (patch) | |
tree | 054f8beb564ebcd8d09a9af89547f4294644f723 /lib | |
parent | 67f1eee8eb47aa3bf9f8d0e45beffc4e46344752 (diff) |
Prepare to provide OBJ_length() and OBJ_get0_data()
OBJ_length() turns the int obj->length into a size_t, so add
an overflow check. While obj->length should never be negative,
who knows...
ok jsing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libcrypto/objects/obj_dat.c | 23 | ||||
-rw-r--r-- | lib/libcrypto/objects/objects.h | 7 |
2 files changed, 28 insertions, 2 deletions
diff --git a/lib/libcrypto/objects/obj_dat.c b/lib/libcrypto/objects/obj_dat.c index bcbc8cef85a..4f7396f669b 100644 --- a/lib/libcrypto/objects/obj_dat.c +++ b/lib/libcrypto/objects/obj_dat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: obj_dat.c,v 1.44 2022/01/07 11:13:54 tb Exp $ */ +/* $OpenBSD: obj_dat.c,v 1.45 2022/01/08 21:36:39 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -816,3 +816,24 @@ OBJ_create(const char *oid, const char *sn, const char *ln) free(buf); return (ok); } + +size_t +OBJ_length(const ASN1_OBJECT *obj) +{ + if (obj == NULL) + return 0; + + if (obj->length < 0) + return 0; + + return obj->length; +} + +const unsigned char * +OBJ_get0_data(const ASN1_OBJECT *obj) +{ + if (obj == NULL) + return NULL; + + return obj->data; +} diff --git a/lib/libcrypto/objects/objects.h b/lib/libcrypto/objects/objects.h index 7a7ba82652e..2aaaefd96b1 100644 --- a/lib/libcrypto/objects/objects.h +++ b/lib/libcrypto/objects/objects.h @@ -1,4 +1,4 @@ -/* $OpenBSD: objects.h,v 1.13 2022/01/08 15:34:59 tb Exp $ */ +/* $OpenBSD: objects.h,v 1.14 2022/01/08 21:36:39 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1105,6 +1105,11 @@ int OBJ_create(const char *oid, const char *sn, const char *ln); void OBJ_cleanup(void); int OBJ_create_objects(BIO *in); +#if defined(LIBRESSL_CRYPTO_INTERNAL) || defined(LIBRESSL_NEXT_API) +size_t OBJ_length(const ASN1_OBJECT *obj); +const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj); +#endif + int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid); int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid); int OBJ_add_sigid(int signid, int dig_id, int pkey_id); |