FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/src/sniffer.c
/* Decrypt input into plain output, 0 on success */
Decrypt input into plain output, 0 on success
Decrypt input into plain output 0 on success
static int Decrypt(WOLFSSL* ssl, byte* output, const byte* input, word32 sz)
{
    int ret = 0;
    (void)output;
    (void)input;
    (void)sz;
    switch (ssl->specs.bulk_cipher_algorithm) {
        #ifdef BUILD_ARC4
        case wolfssl_rc4:
            wc_Arc4Process(ssl->decrypt.arc4, output, input, sz);
            break;
        #endif
        #ifdef BUILD_DES3
        case wolfssl_triple_des:
            ret = wc_Des3_CbcDecrypt(ssl->decrypt.des3, output, input, sz);
            break;
        #endif
        #ifdef BUILD_AES
        case wolfssl_aes:
            ret = wc_AesCbcDecrypt(ssl->decrypt.aes, output, input, sz);
            break;
        #endif
        #ifdef HAVE_HC128
        case wolfssl_hc128:
            wc_Hc128_Process(ssl->decrypt.hc128, output, input, sz);
            break;
        #endif
        #ifdef BUILD_RABBIT
        case wolfssl_rabbit:
            wc_RabbitProcess(ssl->decrypt.rabbit, output, input, sz);
            break;
        #endif
        #ifdef HAVE_CAMELLIA
        case wolfssl_camellia:
            wc_CamelliaCbcDecrypt(ssl->decrypt.cam, output, input, sz);
            break;
        #endif
        #ifdef HAVE_IDEA
        case wolfssl_idea:
            wc_IdeaCbcDecrypt(ssl->decrypt.idea, output, input, sz);
            break;
        #endif
        #ifdef HAVE_AESGCM
        case wolfssl_aes_gcm:
            if (sz >= (word32)(AESGCM_EXP_IV_SZ + ssl->specs.aead_mac_size))
            {
                byte authTag[WOLFSSL_MIN_AUTH_TAG_SZ];
                byte nonce[AESGCM_NONCE_SZ];
                XMEMCPY(nonce, ssl->keys.aead_dec_imp_IV, AESGCM_IMP_IV_SZ);
                XMEMCPY(nonce + AESGCM_IMP_IV_SZ, input, AESGCM_EXP_IV_SZ);
                if (wc_AesGcmEncrypt(ssl->decrypt.aes,
                            output,
                            input + AESGCM_EXP_IV_SZ,
                            sz - AESGCM_EXP_IV_SZ - ssl->specs.aead_mac_size,
                            nonce, AESGCM_NONCE_SZ,
                            authTag, sizeof(authTag),
                            NULL, 0) < 0) {
                    Trace(BAD_DECRYPT);
                    ret = -1;
                }
                ForceZero(nonce, AESGCM_NONCE_SZ);
            }
            else {
                Trace(BAD_DECRYPT_SIZE);
                ret = -1;
            }
            break;
        #endif
        #ifdef HAVE_NULL_CIPHER
        case wolfssl_cipher_null:
            XMEMCPY(output, input, sz);
            break;
        #endif
        default:
            Trace(BAD_DECRYPT_TYPE);
            ret = -1;
            break;
    }
    return ret;
}
static int Decrypt ( WOLFSSL * ssl , byte * output , const byte * input , word32 sz ) { int ret = 0 ; ( void ) output ; ( void ) input ; ( void ) sz ; switch ( ssl -> specs . bulk_cipher_algorithm ) { #ifdef BUILD_ARC4 case wolfssl_rc4 : wc_Arc4Process ( ssl -> decrypt . arc4 , output , input , sz ) ; break ; #endif #ifdef BUILD_DES3 case wolfssl_triple_des : ret = wc_Des3_CbcDecrypt ( ssl -> decrypt . des3 , output , input , sz ) ; break ; #endif #ifdef BUILD_AES case wolfssl_aes : ret = wc_AesCbcDecrypt ( ssl -> decrypt . aes , output , input , sz ) ; break ; #endif #ifdef HAVE_HC128 case wolfssl_hc128 : wc_Hc128_Process ( ssl -> decrypt . hc128 , output , input , sz ) ; break ; #endif #ifdef BUILD_RABBIT case wolfssl_rabbit : wc_RabbitProcess ( ssl -> decrypt . rabbit , output , input , sz ) ; break ; #endif #ifdef HAVE_CAMELLIA case wolfssl_camellia : wc_CamelliaCbcDecrypt ( ssl -> decrypt . cam , output , input , sz ) ; break ; #endif #ifdef HAVE_IDEA case wolfssl_idea : wc_IdeaCbcDecrypt ( ssl -> decrypt . idea , output , input , sz ) ; break ; #endif #ifdef HAVE_AESGCM case wolfssl_aes_gcm : if ( sz >= ( word32 ) ( AESGCM_EXP_IV_SZ + ssl -> specs . aead_mac_size ) ) { byte authTag [ WOLFSSL_MIN_AUTH_TAG_SZ ] ; byte nonce [ AESGCM_NONCE_SZ ] ; XMEMCPY ( nonce , ssl -> keys . aead_dec_imp_IV , AESGCM_IMP_IV_SZ ) ; XMEMCPY ( nonce + AESGCM_IMP_IV_SZ , input , AESGCM_EXP_IV_SZ ) ; if ( wc_AesGcmEncrypt ( ssl -> decrypt . aes , output , input + AESGCM_EXP_IV_SZ , sz - AESGCM_EXP_IV_SZ - ssl -> specs . aead_mac_size , nonce , AESGCM_NONCE_SZ , authTag , sizeof ( authTag ) , NULL , 0 ) < 0 ) { Trace ( BAD_DECRYPT ) ; ret = -1 ; } ForceZero ( nonce , AESGCM_NONCE_SZ ) ; } else { Trace ( BAD_DECRYPT_SIZE ) ; ret = -1 ; } break ; #endif #ifdef HAVE_NULL_CIPHER case wolfssl_cipher_null : XMEMCPY ( output , input , sz ) ; break ; #endif default : Trace ( BAD_DECRYPT_TYPE ) ; ret = -1 ; break ; } return ret ; }
Decrypt input into plain output, 0 on success
Decrypt input into plain output 0 on success
/* scratch buffer, sniffer ignores auth tag*/