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
15 Check DH public key (INTERNAL ONLY, not part of public API)
16 @param key The key you wish to test
17 @return CRYPT_OK if successful
19 int dh_check_pubkey(dh_key *key)
23 int i, digit_count, bits_set = 0, err;
25 LTC_ARGCHK(key != NULL);
27 if ((err = mp_init(&p_minus1)) != CRYPT_OK) {
31 /* avoid: y <= 1 OR y >= p-1 */
32 if ((err = mp_sub_d(key->prime, 1, p_minus1)) != CRYPT_OK) {
35 if (mp_cmp(key->y, p_minus1) != LTC_MP_LT || mp_cmp_d(key->y, 1) != LTC_MP_GT) {
36 err = CRYPT_INVALID_ARG;
40 /* public key must have more than one bit set */
41 digit_count = mp_get_digit_count(key->y);
42 for (i = 0; i < digit_count && bits_set < 2; i++) {
43 digit = mp_get_digit(key->y, i);
45 if (digit & 1) bits_set++;
53 err = CRYPT_INVALID_ARG;
63 /* ref: $Format:%D$ */
64 /* git commit: $Format:%H$ */
65 /* commit time: $Format:%ai$ */