1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
12 @file dsa_shared_secret.c
13 DSA Crypto, Tom St Denis
19 Create a DSA shared secret between two keys
20 @param private_key The private DSA key (the exponent)
21 @param base The base of the exponentiation (allows this to be used for both encrypt and decrypt)
22 @param public_key The public key
23 @param out [out] Destination of the shared secret
24 @param outlen [in/out] The max size and resulting size of the shared secret
25 @return CRYPT_OK if successful
27 int dsa_shared_secret(void *private_key, void *base,
29 unsigned char *out, unsigned long *outlen)
35 LTC_ARGCHK(private_key != NULL);
36 LTC_ARGCHK(public_key != NULL);
37 LTC_ARGCHK(out != NULL);
38 LTC_ARGCHK(outlen != NULL);
41 if ((err = mp_init(&res)) != CRYPT_OK) {
45 if ((err = mp_exptmod(base, private_key, public_key->p, res)) != CRYPT_OK) {
50 x = (unsigned long)mp_unsigned_bin_size(res);
53 err = CRYPT_BUFFER_OVERFLOW;
57 if ((err = mp_to_unsigned_bin(res, out + (x - mp_unsigned_bin_size(res)))) != CRYPT_OK) { goto done; }
67 /* ref: $Format:%D$ */
68 /* git commit: $Format:%H$ */
69 /* commit time: $Format:%ai$ */