int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen ) { if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen ) return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); *olen = 0; if( MBEDTLS_MODE_CFB == ctx->cipher_info->mode || MBEDTLS_MODE_CTR == ctx->cipher_info->mode || MBEDTLS_MODE_GCM == ctx->cipher_info->mode || MBEDTLS_MODE_STREAM == ctx->cipher_info->mode ) { return( 0 ); } if( MBEDTLS_MODE_ECB == ctx->cipher_info->mode ) { if( ctx->unprocessed_len != 0 ) return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); return( 0 ); } #if defined(MBEDTLS_CIPHER_MODE_CBC) if( MBEDTLS_MODE_CBC == ctx->cipher_info->mode ) { int ret = 0; if( MBEDTLS_ENCRYPT == ctx->operation ) { /* check for 'no padding' mode */ if( NULL == ctx->add_padding ) { if( 0 != ctx->unprocessed_len ) return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); return( 0 ); } ctx->add_padding( ctx->unprocessed_data, mbedtls_cipher_get_iv_size( ctx ), ctx->unprocessed_len ); } else if( mbedtls_cipher_get_block_size( ctx ) != ctx->unprocessed_len ) { /* * For decrypt operations, expect a full block, * or an empty block if no padding */ if( NULL == ctx->add_padding && 0 == ctx->unprocessed_len ) return( 0 ); return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); } /* cipher block */ if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, ctx->operation, mbedtls_cipher_get_block_size( ctx ), ctx->iv, ctx->unprocessed_data, output ) ) ) { return( ret ); } /* Set output size for decryption */ if( MBEDTLS_DECRYPT == ctx->operation ) return ctx->get_padding( output, mbedtls_cipher_get_block_size( ctx ), olen ); /* Set output size for encryption */ *olen = mbedtls_cipher_get_block_size( ctx ); return( 0 ); } #else ((void) output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); }
int CipherContext::getIVSize(State & state, mbedtls_cipher_context_t * context) { Stack * stack = state.stack; stack->push<int>(mbedtls_cipher_get_iv_size(context)); return 1; }
result_t Cipher::get_ivSize(int32_t &retVal) { retVal = mbedtls_cipher_get_iv_size(&m_ctx); return 0; }
int cipher_ctx_iv_length(const mbedtls_cipher_context_t *ctx) { return mbedtls_cipher_get_iv_size(ctx); }