summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-01-08 21:36:39 +0000
committertb <>2022-01-08 21:36:39 +0000
commitbe39b26f1f8f0427388ee6657755f16936ca35a5 (patch)
tree466830b7a7d27e0ddc854b19bef96adc5c6550cf /src
parent8a7a673a6b3d10ab5b59599a2211e8c1fabb98e4 (diff)
downloadopenbsd-be39b26f1f8f0427388ee6657755f16936ca35a5.tar.gz
openbsd-be39b26f1f8f0427388ee6657755f16936ca35a5.tar.bz2
openbsd-be39b26f1f8f0427388ee6657755f16936ca35a5.zip
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 'src')
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c23
-rw-r--r--src/lib/libcrypto/objects/objects.h7
2 files changed, 28 insertions, 2 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index bcbc8cef85..4f7396f669 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: obj_dat.c,v 1.44 2022/01/07 11:13:54 tb Exp $ */ 1/* $OpenBSD: obj_dat.c,v 1.45 2022/01/08 21:36:39 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -816,3 +816,24 @@ OBJ_create(const char *oid, const char *sn, const char *ln)
816 free(buf); 816 free(buf);
817 return (ok); 817 return (ok);
818} 818}
819
820size_t
821OBJ_length(const ASN1_OBJECT *obj)
822{
823 if (obj == NULL)
824 return 0;
825
826 if (obj->length < 0)
827 return 0;
828
829 return obj->length;
830}
831
832const unsigned char *
833OBJ_get0_data(const ASN1_OBJECT *obj)
834{
835 if (obj == NULL)
836 return NULL;
837
838 return obj->data;
839}
diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h
index 7a7ba82652..2aaaefd96b 100644
--- a/src/lib/libcrypto/objects/objects.h
+++ b/src/lib/libcrypto/objects/objects.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: objects.h,v 1.13 2022/01/08 15:34:59 tb Exp $ */ 1/* $OpenBSD: objects.h,v 1.14 2022/01/08 21:36:39 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1105,6 +1105,11 @@ int OBJ_create(const char *oid, const char *sn, const char *ln);
1105void OBJ_cleanup(void); 1105void OBJ_cleanup(void);
1106int OBJ_create_objects(BIO *in); 1106int OBJ_create_objects(BIO *in);
1107 1107
1108#if defined(LIBRESSL_CRYPTO_INTERNAL) || defined(LIBRESSL_NEXT_API)
1109size_t OBJ_length(const ASN1_OBJECT *obj);
1110const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
1111#endif
1112
1108int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid); 1113int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid);
1109int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid); 1114int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid);
1110int OBJ_add_sigid(int signid, int dig_id, int pkey_id); 1115int OBJ_add_sigid(int signid, int dig_id, int pkey_id);