FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/curve25519.c
/* Check the public key value (big or little endian)
 *
 * pub     Public key bytes.
 * pubSz   Size of public key in bytes.
 * endian  Public key bytes passed in as big-endian or little-endian.
 * returns BAD_FUNC_ARGS when pub is NULL,
 *         BUFFER_E when size of public key is zero;
 *         ECC_OUT_OF_RANGE_E if the high bit is set;
 *         ECC_BAD_ARG_E if key length is not 32 bytes, public key value is
 *         zero or one; and
 *         0 otherwise.
 */
Check the public key value (big or little endian)
pub     Public key bytes.
pubSz   Size of public key in bytes.
endian  Public key bytes passed in as big-endian or little-endian.
returns BAD_FUNC_ARGS when pub is NULL,
BUFFER_E when size of public key is zero;
ECC_OUT_OF_RANGE_E if the high bit is set;
ECC_BAD_ARG_E if key length is not 32 bytes, public key value is
zero or one; and
0 otherwise.
Check the public key value ( big or little endian ) pub Public key bytes . pubSz Size of public key in bytes . endian Public key bytes passed in as big - endian or little - endian . returns BAD_FUNC_ARGS when pub is NULL BUFFER_E when size of public key is zero ; ECC_OUT_OF_RANGE_E if the high bit is set ; ECC_BAD_ARG_E if key length is not 32 bytes public key value is zero or one ; and 0 otherwise .
int wc_curve25519_check_public(const byte* pub, word32 pubSz, int endian)
{
    word32 i;
    if (pub == NULL)
        return BAD_FUNC_ARG;
    if (pubSz == 0)
        return BUFFER_E;
    if (pubSz != CURVE25519_KEYSIZE)
        return ECC_BAD_ARG_E;
    if (endian == EC25519_LITTLE_ENDIAN) {
        for (i = pubSz - 1; i > 0; i--) {
            if (pub[i] != 0)
                break;
        }
        if (i == 0 && (pub[0] == 0 || pub[0] == 1))
            return ECC_BAD_ARG_E;
        if (pub[CURVE25519_KEYSIZE-1] & 0x80)
            return ECC_OUT_OF_RANGE_E;
    }
    else {
        for (i = 0; i < pubSz-1; i++) {
            if (pub[i] != 0)
                break;
        }
        if (i == pubSz - 1 && (pub[i] == 0 || pub[i] == 1))
            return ECC_BAD_ARG_E;
        if (pub[0] & 0x80)
            return ECC_OUT_OF_RANGE_E;
    }
    return 0;
}
int wc_curve25519_check_public ( const byte * pub , word32 pubSz , int endian ) { word32 i ; if ( pub == NULL ) return BAD_FUNC_ARG ; if ( pubSz == 0 ) return BUFFER_E ; if ( pubSz != CURVE25519_KEYSIZE ) return ECC_BAD_ARG_E ; if ( endian == EC25519_LITTLE_ENDIAN ) { for ( i = pubSz - 1 ; i > 0 ; i -- ) { if ( pub [ i ] != 0 ) break ; } if ( i == 0 && ( pub [ 0 ] == 0 || pub [ 0 ] == 1 ) ) return ECC_BAD_ARG_E ; if ( pub [ CURVE25519_KEYSIZE - 1 ] & 0x80 ) return ECC_OUT_OF_RANGE_E ; } else { for ( i = 0 ; i < pubSz - 1 ; i ++ ) { if ( pub [ i ] != 0 ) break ; } if ( i == pubSz - 1 && ( pub [ i ] == 0 || pub [ i ] == 1 ) ) return ECC_BAD_ARG_E ; if ( pub [ 0 ] & 0x80 ) return ECC_OUT_OF_RANGE_E ; } return 0 ; }
Check the public key value (big or little endian)
 pub     Public key bytes.
Check the public key value ( big or little endian ) pub Public key bytes .
/* Check for empty key data */ /* Check key length */ /* Check for value of zero or one */ /* Check high bit set */ /* Check for value of zero or one */ /* Check high bit set */