int cipher_reset( cipher_context_t *ctx, const unsigned char *iv ) { if( NULL == ctx || NULL == ctx->cipher_info || NULL == iv ) return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; ctx->unprocessed_len = 0; memcpy( ctx->iv, iv, cipher_get_iv_size( ctx ) ); return 0; }
int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen) { int ret = 0; if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen ) return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; *olen = 0; if( POLARSSL_MODE_CFB == ctx->cipher_info->mode || POLARSSL_MODE_CTR == ctx->cipher_info->mode || POLARSSL_MODE_NULL == ctx->cipher_info->mode ) { return 0; } if( POLARSSL_MODE_CBC == ctx->cipher_info->mode ) { if( POLARSSL_ENCRYPT == ctx->operation ) { add_pkcs_padding( ctx->unprocessed_data, cipher_get_iv_size( ctx ), ctx->unprocessed_len ); } else if ( cipher_get_block_size( ctx ) != ctx->unprocessed_len ) { /* For decrypt operations, expect a full block */ return POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED; } /* cipher block */ if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, ctx->operation, cipher_get_block_size( ctx ), ctx->iv, ctx->unprocessed_data, output ) ) ) { return ret; } /* Set output size for decryption */ if( POLARSSL_DECRYPT == ctx->operation ) return get_pkcs_padding( output, cipher_get_block_size( ctx ), olen ); /* Set output size for encryption */ *olen = cipher_get_block_size( ctx ); return 0; } return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; }
int cipher_finish( cipher_context_t *ctx, unsigned char *output, size_t *olen ) { if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen ) return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA ); *olen = 0; if( POLARSSL_MODE_CFB == ctx->cipher_info->mode || POLARSSL_MODE_CTR == ctx->cipher_info->mode || POLARSSL_MODE_GCM == ctx->cipher_info->mode || POLARSSL_MODE_STREAM == ctx->cipher_info->mode ) { return( 0 ); } if( POLARSSL_MODE_ECB == ctx->cipher_info->mode ) { if( ctx->unprocessed_len != 0 ) return( POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED ); return( 0 ); } #if defined(POLARSSL_CIPHER_MODE_CBC) if( POLARSSL_MODE_CBC == ctx->cipher_info->mode ) { int ret = 0; if( POLARSSL_ENCRYPT == ctx->operation ) { /* check for 'no padding' mode */ if( NULL == ctx->add_padding ) { if( 0 != ctx->unprocessed_len ) return( POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED ); return( 0 ); } ctx->add_padding( ctx->unprocessed_data, cipher_get_iv_size( ctx ), ctx->unprocessed_len ); } else if( 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( POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED ); } /* cipher block */ if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, ctx->operation, cipher_get_block_size( ctx ), ctx->iv, ctx->unprocessed_data, output ) ) ) { return( ret ); } /* Set output size for decryption */ if( POLARSSL_DECRYPT == ctx->operation ) return ctx->get_padding( output, cipher_get_block_size( ctx ), olen ); /* Set output size for encryption */ *olen = cipher_get_block_size( ctx ); return( 0 ); } #else ((void) output); #endif /* POLARSSL_CIPHER_MODE_CBC */ return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE ); }
int cipher_ctx_iv_length (const cipher_context_t *ctx) { return cipher_get_iv_size(ctx); }
result_t Cipher::get_ivSize(int32_t &retVal) { retVal = cipher_get_iv_size(&m_ctx); return 0; }