summaryrefslogtreecommitdiffstats
path: root/crypto/dh
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2011-03-08 19:07:26 +0000
committerDr. Stephen Henson <steve@openssl.org>2013-10-01 14:01:17 +0100
commit6c4b3514d740020be9bf7c757930f8ca536622ee (patch)
treeaed1e7dfaaabd83f4efa21ee509357f30d4ba11d /crypto/dh
parentd84cca7447c1d832807e6d23c01e760054357727 (diff)
New SP 800-56A compliant version of DH_compute_key().
(cherry picked from commit bc91494e064ebdcff68f987947f97e404fbca0b5)
Diffstat (limited to 'crypto/dh')
-rw-r--r--crypto/dh/dh.h1
-rw-r--r--crypto/dh/dh_key.c15
2 files changed, 16 insertions, 0 deletions
diff --git a/crypto/dh/dh.h b/crypto/dh/dh.h
index 523d3464ac..a4095c1adb 100644
--- a/crypto/dh/dh.h
+++ b/crypto/dh/dh.h
@@ -213,6 +213,7 @@ int DH_check(const DH *dh,int *codes);
int DH_check_pub_key(const DH *dh,const BIGNUM *pub_key, int *codes);
int DH_generate_key(DH *dh);
int DH_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh);
+int DH_compute_key_padded(unsigned char *key,const BIGNUM *pub_key,DH *dh);
DH * d2i_DHparams(DH **a,const unsigned char **pp, long length);
int i2d_DHparams(const DH *a,unsigned char **pp);
DH * d2i_DHxparams(DH **a,const unsigned char **pp, long length);
diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c
index 89a74db4e6..6cb0d02256 100644
--- a/crypto/dh/dh_key.c
+++ b/crypto/dh/dh_key.c
@@ -97,6 +97,21 @@ int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
return dh->meth->compute_key(key, pub_key, dh);
}
+int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh)
+ {
+ int rv, pad;
+ rv = dh->meth->compute_key(key, pub_key, dh);
+ if (rv <= 0)
+ return rv;
+ pad = BN_num_bytes(dh->p) - rv;
+ if (pad > 0)
+ {
+ memmove(key + pad, key, rv);
+ memset(key, 0, pad);
+ }
+ return rv + pad;
+ }
+
static DH_METHOD dh_ossl = {
"OpenSSL DH Method",
generate_key,