summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2018-02-18 12:53:46 +0000
committertb <>2018-02-18 12:53:46 +0000
commit57e413e44047c6de5afd81409c4917b1071cb777 (patch)
tree2eea48ceda5c1ecb2eab68df4708270f46b1a6fd
parentd7ec2573e9647e327eb8fddb8465b70fc269f8be (diff)
downloadopenbsd-57e413e44047c6de5afd81409c4917b1071cb777.tar.gz
openbsd-57e413e44047c6de5afd81409c4917b1071cb777.tar.bz2
openbsd-57e413e44047c6de5afd81409c4917b1071cb777.zip
Provide RSA_{g,s}et0_factors()
ok jsing
-rw-r--r--src/lib/libcrypto/Symbols.list2
-rw-r--r--src/lib/libcrypto/rsa/rsa.h4
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c29
3 files changed, 33 insertions, 2 deletions
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index 8f18580b55..79d82d49bc 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -2211,6 +2211,7 @@ RSA_flags
2211RSA_free 2211RSA_free
2212RSA_generate_key 2212RSA_generate_key
2213RSA_generate_key_ex 2213RSA_generate_key_ex
2214RSA_get0_factors
2214RSA_get0_key 2215RSA_get0_key
2215RSA_get_default_method 2216RSA_get_default_method
2216RSA_get_ex_data 2217RSA_get_ex_data
@@ -2236,6 +2237,7 @@ RSA_private_decrypt
2236RSA_private_encrypt 2237RSA_private_encrypt
2237RSA_public_decrypt 2238RSA_public_decrypt
2238RSA_public_encrypt 2239RSA_public_encrypt
2240RSA_set0_factors
2239RSA_set0_key 2241RSA_set0_key
2240RSA_set_default_method 2242RSA_set_default_method
2241RSA_set_ex_data 2243RSA_set_ex_data
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h
index 7e28a8766c..51b06ba6aa 100644
--- a/src/lib/libcrypto/rsa/rsa.h
+++ b/src/lib/libcrypto/rsa/rsa.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa.h,v 1.33 2018/02/18 12:52:13 tb Exp $ */ 1/* $OpenBSD: rsa.h,v 1.34 2018/02/18 12:53:46 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 *
@@ -399,6 +399,8 @@ void *RSA_get_ex_data(const RSA *r, int idx);
399int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d); 399int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
400void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, 400void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e,
401 const BIGNUM **d); 401 const BIGNUM **d);
402void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
403int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
402 404
403RSA *RSAPublicKey_dup(RSA *rsa); 405RSA *RSAPublicKey_dup(RSA *rsa);
404RSA *RSAPrivateKey_dup(RSA *rsa); 406RSA *RSAPrivateKey_dup(RSA *rsa);
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index 2a73364e70..c31aa935b7 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_lib.c,v 1.32 2018/02/17 13:47:36 tb Exp $ */ 1/* $OpenBSD: rsa_lib.c,v 1.33 2018/02/18 12:53:46 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 *
@@ -289,3 +289,30 @@ RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
289 if (d != NULL) 289 if (d != NULL)
290 *d = r->d; 290 *d = r->d;
291} 291}
292
293void
294RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
295{
296 if (p != NULL)
297 *p = r->p;
298 if (q != NULL)
299 *q = r->q;
300}
301
302int
303RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
304{
305 if ((r->p == NULL && p == NULL) || (r->q == NULL && q == NULL))
306 return 0;
307
308 if (p != NULL) {
309 BN_free(r->p);
310 r->p = p;
311 }
312 if (q != NULL) {
313 BN_free(r->q);
314 r->q = q;
315 }
316
317 return 1;
318}