Skip to content

Commit

Permalink
Add various 1.1.0 accessors.
Browse files Browse the repository at this point in the history
This gets cURL building against both BoringSSL as it is and BoringSSL
with OPENSSL_VERSION_NUMBER set to 1.1.0.

BUG=91

Change-Id: I5be73b84df701fe76f3055b1239ae4704a931082
Reviewed-on: https://boringssl-review.googlesource.com/10180
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
  • Loading branch information
davidben authored and CQ bot account: commit-bot@chromium.org committed Aug 10, 2016
1 parent 3f26a49 commit 5a91503
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crypto/dh/dh.c
Expand Up @@ -115,6 +115,29 @@ void DH_free(DH *dh) {
OPENSSL_free(dh);
}

void DH_get0_key(const DH *dh, const BIGNUM **out_pub_key,
const BIGNUM **out_priv_key) {
if (out_pub_key != NULL) {
*out_pub_key = dh->pub_key;
}
if (out_priv_key != NULL) {
*out_priv_key = dh->priv_key;
}
}

void DH_get0_pqg(const DH *dh, const BIGNUM **out_p, const BIGNUM **out_q,
const BIGNUM **out_g) {
if (out_p != NULL) {
*out_p = dh->p;
}
if (out_q != NULL) {
*out_q = dh->q;
}
if (out_g != NULL) {
*out_g = dh->g;
}
}

int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator, BN_GENCB *cb) {
/* We generate DH parameters as follows
* find a prime q which is prime_bits/2 bits long.
Expand Down
23 changes: 23 additions & 0 deletions crypto/dsa/dsa.c
Expand Up @@ -129,6 +129,29 @@ int DSA_up_ref(DSA *dsa) {
return 1;
}

void DSA_get0_key(const DSA *dsa, const BIGNUM **out_pub_key,
const BIGNUM **out_priv_key) {
if (out_pub_key != NULL) {
*out_pub_key = dsa->pub_key;
}
if (out_priv_key != NULL) {
*out_priv_key = dsa->priv_key;
}
}

void DSA_get0_pqg(const DSA *dsa, const BIGNUM **out_p, const BIGNUM **out_q,
const BIGNUM **out_g) {
if (out_p != NULL) {
*out_p = dsa->p;
}
if (out_q != NULL) {
*out_q = dsa->q;
}
if (out_g != NULL) {
*out_g = dsa->g;
}
}

int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in,
size_t seed_len, int *out_counter,
unsigned long *out_h, BN_GENCB *cb) {
Expand Down
2 changes: 2 additions & 0 deletions crypto/evp/evp.c
Expand Up @@ -302,6 +302,8 @@ EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) {
return ec_key;
}

DH *EVP_PKEY_get0_DH(EVP_PKEY *pkey) { return NULL; }

int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) {
if (!EVP_PKEY_set_type(pkey, type)) {
return 0;
Expand Down
36 changes: 36 additions & 0 deletions crypto/rsa/rsa.c
Expand Up @@ -169,6 +169,42 @@ int RSA_up_ref(RSA *rsa) {
return 1;
}

void RSA_get0_key(const RSA *rsa, const BIGNUM **out_n, const BIGNUM **out_e,
const BIGNUM **out_d) {
if (out_n != NULL) {
*out_n = rsa->n;
}
if (out_e != NULL) {
*out_e = rsa->e;
}
if (out_d != NULL) {
*out_d = rsa->d;
}
}

void RSA_get0_factors(const RSA *rsa, const BIGNUM **out_p,
const BIGNUM **out_q) {
if (out_p != NULL) {
*out_p = rsa->p;
}
if (out_q != NULL) {
*out_q = rsa->q;
}
}

void RSA_get0_crt_params(const RSA *rsa, const BIGNUM **out_dmp1,
const BIGNUM **out_dmq1, const BIGNUM **out_iqmp) {
if (out_dmp1 != NULL) {
*out_dmp1 = rsa->dmp1;
}
if (out_dmq1 != NULL) {
*out_dmq1 = rsa->dmq1;
}
if (out_iqmp != NULL) {
*out_iqmp = rsa->iqmp;
}
}

int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) {
if (rsa->meth->keygen) {
return rsa->meth->keygen(rsa, bits, e_value, cb);
Expand Down
5 changes: 5 additions & 0 deletions crypto/x509/x509_set.c
Expand Up @@ -147,3 +147,8 @@ int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
return (0);
return (X509_PUBKEY_set(&(x->cert_info->key), pkey));
}

STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x)
{
return x->cert_info->extensions;
}
14 changes: 14 additions & 0 deletions include/openssl/dh.h
Expand Up @@ -85,6 +85,20 @@ OPENSSL_EXPORT void DH_free(DH *dh);
OPENSSL_EXPORT int DH_up_ref(DH *dh);


/* Properties. */

/* DH_get0_key sets |*out_pub_key| and |*out_priv_key|, if non-NULL, to |dh|'s
* public and private key, respectively. If |dh| is a public key, the private
* key will be set to NULL. */
OPENSSL_EXPORT void DH_get0_key(const DH *dh, const BIGNUM **out_pub_key,
const BIGNUM **out_priv_key);

/* DH_get0_pqg sets |*out_p|, |*out_q|, and |*out_g|, if non-NULL, to |dh|'s p,
* q, and g parameters, respectively. */
OPENSSL_EXPORT void DH_get0_pqg(const DH *dh, const BIGNUM **out_p,
const BIGNUM **out_q, const BIGNUM **out_g);


/* Standard parameters.
*
* These functions return new DH objects with standard parameters. They return
Expand Down
14 changes: 14 additions & 0 deletions include/openssl/dsa.h
Expand Up @@ -88,6 +88,20 @@ OPENSSL_EXPORT void DSA_free(DSA *dsa);
OPENSSL_EXPORT int DSA_up_ref(DSA *dsa);


/* Properties. */

/* DSA_get0_key sets |*out_pub_key| and |*out_priv_key|, if non-NULL, to |dsa|'s
* public and private key, respectively. If |dsa| is a public key, the private
* key will be set to NULL. */
OPENSSL_EXPORT void DSA_get0_key(const DSA *dsa, const BIGNUM **out_pub_key,
const BIGNUM **out_priv_key);

/* DSA_get0_pqg sets |*out_p|, |*out_q|, and |*out_g|, if non-NULL, to |dsa|'s
* p, q, and g parameters, respectively. */
OPENSSL_EXPORT void DSA_get0_pqg(const DSA *dsa, const BIGNUM **out_p,
const BIGNUM **out_q, const BIGNUM **out_g);


/* Parameter generation. */

/* DSA_generate_parameters_ex generates a set of DSA parameters by following
Expand Down
3 changes: 3 additions & 0 deletions include/openssl/evp.h
Expand Up @@ -721,6 +721,9 @@ OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **out,
OPENSSL_EXPORT EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **out, const uint8_t **inp,
long len);

/* EVP_PKEY_get0_DH returns NULL. */
OPENSSL_EXPORT DH *EVP_PKEY_get0_DH(EVP_PKEY *pkey);


/* Private structures. */

Expand Down
24 changes: 24 additions & 0 deletions include/openssl/rsa.h
Expand Up @@ -87,6 +87,30 @@ OPENSSL_EXPORT void RSA_free(RSA *rsa);
OPENSSL_EXPORT int RSA_up_ref(RSA *rsa);


/* Properties. */

/* RSA_get0_key sets |*out_n|, |*out_e|, and |*out_d|, if non-NULL, to |rsa|'s
* modulus, public exponent, and private exponent, respectively. If |rsa| is a
* public key, the private exponent will be set to NULL. */
OPENSSL_EXPORT void RSA_get0_key(const RSA *rsa, const BIGNUM **out_n,
const BIGNUM **out_e, const BIGNUM **out_d);

/* RSA_get0_factors sets |*out_p| and |*out_q|, if non-NULL, to |rsa|'s prime
* factors. If |rsa| is a public key, they will be set to NULL. If |rsa| is a
* multi-prime key, only the first two prime factors will be reported. */
OPENSSL_EXPORT void RSA_get0_factors(const RSA *rsa, const BIGNUM **out_p,
const BIGNUM **out_q);

/* RSA_get0_crt_params sets |*out_dmp1|, |*out_dmq1|, and |*out_iqmp|, if
* non-NULL, to |rsa|'s CRT parameters. These are d (mod p-1), d (mod q-1) and
* q^-1 (mod p), respectively. If |rsa| is a public key, each parameter will be
* set to NULL. If |rsa| is a multi-prime key, only the CRT parameters for the
* first two primes will be reported. */
OPENSSL_EXPORT void RSA_get0_crt_params(const RSA *rsa, const BIGNUM **out_dmp1,
const BIGNUM **out_dmq1,
const BIGNUM **out_iqmp);


/* Key generation. */

/* RSA_generate_key_ex generates a new RSA key where the modulus has size
Expand Down
1 change: 1 addition & 0 deletions include/openssl/x509.h
Expand Up @@ -858,6 +858,7 @@ OPENSSL_EXPORT int X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
OPENSSL_EXPORT EVP_PKEY * X509_get_pubkey(X509 *x);
OPENSSL_EXPORT ASN1_BIT_STRING * X509_get0_pubkey_bitstr(const X509 *x);
OPENSSL_EXPORT int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
OPENSSL_EXPORT STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x);

OPENSSL_EXPORT int X509_REQ_set_version(X509_REQ *x,long version);
OPENSSL_EXPORT int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
Expand Down

0 comments on commit 5a91503

Please sign in to comment.