Add rc4 to EVP_CipherUpdate

This commit is contained in:
Takashi Kojo 2017-03-03 13:13:02 +09:00 committed by Jacob Barthelmeh
parent 21021aa408
commit 5237a25699
2 changed files with 21 additions and 11 deletions

View File

@ -13247,7 +13247,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
ctx->bufUsed = 0;
ctx->lastUsed = 0;
ctx->flags = 0;
ret = 0;
#ifndef NO_AES
if (ctx->cipherType == AES_128_CBC_TYPE ||
(type && XSTRNCMP(type, EVP_AES_128_CBC, EVP_AES_SIZE) == 0)) {
@ -13518,6 +13518,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
WOLFSSL_MSG("ARC4");
ctx->cipherType = ARC4_TYPE;
ctx->flags = WOLFSSL_EVP_CIPH_STREAM_CIPHER;
ctx->block_size = 1;
if (ctx->keyLen == 0) /* user may have already set */
ctx->keyLen = 16; /* default to 128 */
if (key)
@ -13532,6 +13533,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
ctx->cipherType = IDEA_CBC_TYPE;
ctx->flags = WOLFSSL_EVP_CIPH_CBC_MODE;
ctx->keyLen = IDEA_KEY_SIZE;
ctx->block_size = 8;
if (enc == 0 || enc == 1)
ctx->enc = enc ? 1 : 0;
if (key) {
@ -13551,6 +13553,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
WOLFSSL_MSG("NULL cipher");
ctx->cipherType = NULL_CIPHER_TYPE;
ctx->keyLen = 0;
ctx->block_size = 16;
ret = 0; /* success */
}

View File

@ -272,8 +272,16 @@ static int evpCipherBlock(WOLFSSL_EVP_CIPHER_CTX *ctx,
case DES_EDE3_ECB_TYPE:
ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, out, in, inl);
break;
#endif /* WOLFSSL_DES_ECB */
#endif /* !NO_DES3 */
#endif
#endif
#ifndef NO_RC4
case ARC4_TYPE:
if (ctx->enc)
wc_Arc4Process(&ctx->cipher.arc4, out, in, inl);
else
wc_Arc4Process(&ctx->cipher.arc4, out, in, inl);
break;
#endif
default:
return 0;
}
@ -306,7 +314,6 @@ WOLFSSL_API int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx,
in += fill;
}
if((ctx->enc == 0)&& (ctx->lastUsed == 1)){
//printf("(ctx->enc == 0)&& (ctx->lastUsed == 1)\n");
PRINT_BUF(ctx->lastBlock, ctx->block_size);
XMEMCPY(out, ctx->lastBlock, ctx->block_size);
*outl+= ctx->block_size;
@ -329,24 +336,20 @@ WOLFSSL_API int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx,
}
blocks = inl / ctx->block_size;
//printf("blocks=%d\n", blocks);
if (blocks > 0) {
/* process blocks */
if (evpCipherBlock(ctx, out, in, blocks * ctx->block_size) == 0)
return 0;
PRINT_BUF(in, ctx->block_size);
PRINT_BUF(out,ctx->block_size);
PRINT_BUF(in, ctx->block_size*blocks);
PRINT_BUF(out,ctx->block_size*blocks);
inl -= ctx->block_size * blocks;
in += ctx->block_size * blocks;
if(ctx->enc == 0){
//printf("(ctx->enc == 0)\n");
if ((ctx->flags & WOLFSSL_EVP_CIPH_NO_PADDING) /* ||
((inl % ctx->block_size) == 0)*/){
if ((ctx->flags & WOLFSSL_EVP_CIPH_NO_PADDING)){
ctx->lastUsed = 0;
XMEMCPY(ctx->lastBlock, &out[ctx->block_size * blocks], ctx->block_size);
*outl+= ctx->block_size * blocks;
} else {
//printf("blocks=%d, ctx->lastUsed = 1;\n", blocks);
ctx->lastUsed = 1;
XMEMCPY(ctx->lastBlock, &out[ctx->block_size * (blocks-1)], ctx->block_size);
*outl+= ctx->block_size * (blocks-1);
@ -562,6 +565,10 @@ unsigned long WOLFSSL_CIPHER_mode(const WOLFSSL_EVP_CIPHER *cipher)
case DES_ECB_TYPE:
case DES_EDE3_ECB_TYPE:
return WOLFSSL_EVP_CIPH_ECB_MODE ;
#endif
#ifndef NO_RC4
case ARC4_TYPE:
return EVP_CIPH_STREAM_CIPHER;
#endif
default:
return 0;