FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/asn.c
/* The wc_DhParamsLoad function also loads DH params, but directly into buffers, not DhKey */
The wc_DhParamsLoad function also loads DH params, but directly into buffers, not DhKey
The wc_DhParamsLoad function also loads DH params but directly into buffers not DhKey
int wc_DhKeyDecode(const byte* input, word32* inOutIdx, DhKey* key, word32 inSz)
{
    int ret = 0;
    int length;
#ifdef WOLFSSL_DH_EXTRA
    #if !defined(HAVE_FIPS) || \
        (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
    word32 oid = 0, temp = 0;
    #endif
#endif
    WOLFSSL_ENTER("wc_DhKeyDecode");
    if (inOutIdx == NULL)
        return BAD_FUNC_ARG;
    if (GetSequence(input, inOutIdx, &length, inSz) < 0)
        return ASN_PARSE_E;
#ifdef WOLFSSL_DH_EXTRA
    #if !defined(HAVE_FIPS) || \
        (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
    temp = *inOutIdx;
    #endif
#endif
    if (GetInt(&key->p,  input, inOutIdx, inSz) < 0 ||
        GetInt(&key->g,  input, inOutIdx, inSz) < 0) {
        ret = ASN_DH_KEY_E;
    }
#ifdef WOLFSSL_DH_EXTRA
    #if !defined(HAVE_FIPS) || \
        (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
    if (ret == ASN_DH_KEY_E) {
        *inOutIdx = temp;
        if (GetASNInt(input, inOutIdx, &length, inSz) < 0) {
            return ASN_PARSE_E;
        }
        *inOutIdx += length;
        if (GetSequence(input, inOutIdx, &length, inSz) < 0)
            return ASN_PARSE_E;
        ret = GetObjectId(input, inOutIdx, &oid, oidKeyType, inSz);
        if (oid != DHk || ret < 0)
            return ASN_DH_KEY_E;
        if (GetSequence(input, inOutIdx, &length, inSz) < 0)
            return ASN_PARSE_E;
        if (GetInt(&key->p, input, inOutIdx, inSz) < 0 ||
            GetInt(&key->g, input, inOutIdx, inSz) < 0) {
            return ASN_DH_KEY_E;
        }
    }
    temp = *inOutIdx;
    ret = (CheckBitString(input, inOutIdx, &length, inSz, 0, NULL) == 0);
    if (ret > 0) {
        if (GetInt(&key->pub, input, inOutIdx, inSz) == 0) {
            WOLFSSL_MSG("Found Public Key");
            ret = 0;
        }
    } else {
        *inOutIdx = temp;
        ret = (GetOctetString(input, inOutIdx, &length, inSz) >= 0);
        if (ret > 0) {
            if (GetInt(&key->priv, input, inOutIdx, inSz) == 0) {
                WOLFSSL_MSG("Found Private Key");
                ret = mp_exptmod(&key->g, &key->priv, &key->p, &key->pub);
            }
        } else {
            *inOutIdx = temp;
            ret = 0;
        }
    }
    #endif 
#endif 
    WOLFSSL_LEAVE("wc_DhKeyDecode", ret);
    return ret;
}
int wc_DhKeyDecode ( const byte * input , word32 * inOutIdx , DhKey * key , word32 inSz ) { int ret = 0 ; int length ; #ifdef WOLFSSL_DH_EXTRA #if ! defined ( HAVE_FIPS ) || ( defined ( HAVE_FIPS_VERSION ) && ( HAVE_FIPS_VERSION > 2 ) ) word32 oid = 0 , temp = 0 ; #endif #endif WOLFSSL_ENTER ( " " ) ; if ( inOutIdx == NULL ) return BAD_FUNC_ARG ; if ( GetSequence ( input , inOutIdx , & length , inSz ) < 0 ) return ASN_PARSE_E ; #ifdef WOLFSSL_DH_EXTRA #if ! defined ( HAVE_FIPS ) || ( defined ( HAVE_FIPS_VERSION ) && ( HAVE_FIPS_VERSION > 2 ) ) temp = * inOutIdx ; #endif #endif if ( GetInt ( & key -> p , input , inOutIdx , inSz ) < 0 || GetInt ( & key -> g , input , inOutIdx , inSz ) < 0 ) { ret = ASN_DH_KEY_E ; } #ifdef WOLFSSL_DH_EXTRA #if ! defined ( HAVE_FIPS ) || ( defined ( HAVE_FIPS_VERSION ) && ( HAVE_FIPS_VERSION > 2 ) ) if ( ret == ASN_DH_KEY_E ) { * inOutIdx = temp ; if ( GetASNInt ( input , inOutIdx , & length , inSz ) < 0 ) { return ASN_PARSE_E ; } * inOutIdx += length ; if ( GetSequence ( input , inOutIdx , & length , inSz ) < 0 ) return ASN_PARSE_E ; ret = GetObjectId ( input , inOutIdx , & oid , oidKeyType , inSz ) ; if ( oid != DHk || ret < 0 ) return ASN_DH_KEY_E ; if ( GetSequence ( input , inOutIdx , & length , inSz ) < 0 ) return ASN_PARSE_E ; if ( GetInt ( & key -> p , input , inOutIdx , inSz ) < 0 || GetInt ( & key -> g , input , inOutIdx , inSz ) < 0 ) { return ASN_DH_KEY_E ; } } temp = * inOutIdx ; ret = ( CheckBitString ( input , inOutIdx , & length , inSz , 0 , NULL ) == 0 ) ; if ( ret > 0 ) { if ( GetInt ( & key -> pub , input , inOutIdx , inSz ) == 0 ) { WOLFSSL_MSG ( " " ) ; ret = 0 ; } } else { * inOutIdx = temp ; ret = ( GetOctetString ( input , inOutIdx , & length , inSz ) >= 0 ) ; if ( ret > 0 ) { if ( GetInt ( & key -> priv , input , inOutIdx , inSz ) == 0 ) { WOLFSSL_MSG ( " " ) ; ret = mp_exptmod ( & key -> g , & key -> priv , & key -> p , & key -> pub ) ; } } else { * inOutIdx = temp ; ret = 0 ; } } #endif #endif WOLFSSL_LEAVE ( " " , ret ) ; return ret ; }
The wc_DhParamsLoad function also loads DH params, but directly into buffers, not DhKey
The wc_DhParamsLoad function also loads DH params but directly into buffers not DhKey
/* Assume input started after 1.2.840.113549.1.3.1 dhKeyAgreement */ /* If ASN_DH_KEY_E: Check if input started at beginning of key */ /* the version (0) */ /* Size of dhKeyAgreement section */ /* Check for dhKeyAgreement */ /* Found Bit String */ /* Found Octet String */ /* Compute public */ /* Don't use length from failed CheckBitString/GetOctetString */ /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */ /* WOLFSSL_DH_EXTRA */