FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/dh.c
/**
 * Quick validity check of public key value against prime.
 * Checks are:
 *   - Public key not 0 or 1
 *   - Public key not equal to prime or prime - 1
 *   - Public key not bigger than prime.
 *
 * prime    Big-endian encoding of prime in bytes.
 * primeSz  Size of prime in bytes.
 * pub      Big-endian encoding of public key in bytes.
 * pubSz    Size of public key in bytes.
 */
Quick validity check of public key value against prime.
Checks are:
- Public key not 0 or 1
- Public key not equal to prime or prime - 1
- Public key not bigger than prime.

prime    Big-endian encoding of prime in bytes.
primeSz  Size of prime in bytes.
pub      Big-endian encoding of public key in bytes.
pubSz    Size of public key in bytes.
Quick validity check of public key value against prime . Checks are : - Public key not 0 or 1 - Public key not equal to prime or prime - 1 - Public key not bigger than prime . prime Big - endian encoding of prime in bytes . primeSz Size of prime in bytes . pub Big - endian encoding of public key in bytes . pubSz Size of public key in bytes .
int wc_DhCheckPubValue(const byte* prime, word32 primeSz, const byte* pub,
                       word32 pubSz)
{
    int ret = 0;
    word32 i;
    for (i = 0; i < pubSz && pub[i] == 0; i++) {
    }
    pubSz -= i;
    pub += i;
    if (pubSz == 0 || (pubSz == 1 && pub[0] == 1))
        ret = MP_VAL;
    else if (pubSz == primeSz) {
        for (i = 0; i < pubSz-1 && pub[i] == prime[i]; i++) {
        }
        if (i == pubSz-1 && (pub[i] == prime[i] || pub[i] == prime[i] - 1))
            ret = MP_VAL;
        else if (pub[i] > prime[i])
            ret = MP_VAL;
    }
    else if (pubSz > primeSz)
        ret = MP_VAL;
    return ret;
}
int wc_DhCheckPubValue ( const byte * prime , word32 primeSz , const byte * pub , word32 pubSz ) { int ret = 0 ; word32 i ; for ( i = 0 ; i < pubSz && pub [ i ] == 0 ; i ++ ) { } pubSz -= i ; pub += i ; if ( pubSz == 0 || ( pubSz == 1 && pub [ 0 ] == 1 ) ) ret = MP_VAL ; else if ( pubSz == primeSz ) { for ( i = 0 ; i < pubSz - 1 && pub [ i ] == prime [ i ] ; i ++ ) { } if ( i == pubSz - 1 && ( pub [ i ] == prime [ i ] || pub [ i ] == prime [ i ] - 1 ) ) ret = MP_VAL ; else if ( pub [ i ] > prime [ i ] ) ret = MP_VAL ; } else if ( pubSz > primeSz ) ret = MP_VAL ; return ret ; }
Quick validity check of public key value against prime.
Quick validity check of public key value against prime .