forked from wolfSSL/wolfssl
move AES oneshot calls out of aes.[hc]
This commit is contained in:
@@ -74,6 +74,7 @@ endif
|
|||||||
|
|
||||||
src_libwolfssl_la_SOURCES += \
|
src_libwolfssl_la_SOURCES += \
|
||||||
wolfcrypt/src/logging.c \
|
wolfcrypt/src/logging.c \
|
||||||
|
wolfcrypt/src/wc_encrypt.c \
|
||||||
wolfcrypt/src/wc_port.c \
|
wolfcrypt/src/wc_port.c \
|
||||||
wolfcrypt/src/error.c
|
wolfcrypt/src/error.c
|
||||||
|
|
||||||
|
@@ -57,6 +57,7 @@
|
|||||||
#include <wolfssl/wolfcrypt/md4.h>
|
#include <wolfssl/wolfcrypt/md4.h>
|
||||||
#include <wolfssl/wolfcrypt/md5.h>
|
#include <wolfssl/wolfcrypt/md5.h>
|
||||||
#include <wolfssl/wolfcrypt/arc4.h>
|
#include <wolfssl/wolfcrypt/arc4.h>
|
||||||
|
#include <wolfssl/wolfcrypt/wc_encrypt.h>
|
||||||
#ifdef WOLFSSL_SHA512
|
#ifdef WOLFSSL_SHA512
|
||||||
#include <wolfssl/wolfcrypt/sha512.h>
|
#include <wolfssl/wolfcrypt/sha512.h>
|
||||||
#endif
|
#endif
|
||||||
|
@@ -55,19 +55,6 @@ int wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
|
|
||||||
const byte* key, word32 keySz, const byte* iv)
|
|
||||||
{
|
|
||||||
return AesCbcDecryptWithKey(out, in, inSz, key, keySz, iv);
|
|
||||||
}
|
|
||||||
|
|
||||||
int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
|
|
||||||
const byte* key, word32 keySz, const byte* iv)
|
|
||||||
{
|
|
||||||
return AesCbcDecryptWithKey(out, in, inSz, key, keySz, iv);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* AES-CTR */
|
/* AES-CTR */
|
||||||
#ifdef WOLFSSL_AES_COUNTER
|
#ifdef WOLFSSL_AES_COUNTER
|
||||||
void wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
void wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
||||||
@@ -1727,59 +1714,6 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
|
|
||||||
const byte* key, word32 keySz, const byte* iv)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
|
||||||
Aes* aes = NULL;
|
|
||||||
#else
|
|
||||||
Aes aes[1];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
|
||||||
aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
|
||||||
if (aes == NULL)
|
|
||||||
return MEMORY_E;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret = wc_AesSetKey(aes, key, keySz, iv, AES_DECRYPTION);
|
|
||||||
if (ret == 0)
|
|
||||||
ret = wc_AesCbcDecrypt(aes, out, in, inSz);
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
|
||||||
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
|
|
||||||
const byte* key, word32 keySz, const byte* iv)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
|
||||||
Aes* aes = NULL;
|
|
||||||
#else
|
|
||||||
Aes aes[1];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
|
||||||
aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
|
||||||
if (aes == NULL)
|
|
||||||
return MEMORY_E;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret = wc_AesSetKey(aes, key, keySz, iv, AES_ENCRYPTION);
|
|
||||||
if (ret == 0)
|
|
||||||
ret = wc_AesCbcEncrypt(aes, out, in, inSz);
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
|
||||||
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* AES-DIRECT */
|
/* AES-DIRECT */
|
||||||
|
87
wolfcrypt/src/wc_encrypt.c
Normal file
87
wolfcrypt/src/wc_encrypt.c
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/* wc_encrypt.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2015 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
#include <wolfssl/wolfcrypt/aes.h>
|
||||||
|
#include <wolfssl/wolfcrypt/wc_encrypt.h>
|
||||||
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_AES
|
||||||
|
int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
|
||||||
|
const byte* key, word32 keySz, const byte* iv)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
Aes* aes = NULL;
|
||||||
|
#else
|
||||||
|
Aes aes[1];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
if (aes == NULL)
|
||||||
|
return MEMORY_E;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ret = wc_AesSetKey(aes, key, keySz, iv, AES_DECRYPTION);
|
||||||
|
if (ret == 0)
|
||||||
|
ret = wc_AesCbcDecrypt(aes, out, in, inSz);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
|
||||||
|
const byte* key, word32 keySz, const byte* iv)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
Aes* aes = NULL;
|
||||||
|
#else
|
||||||
|
Aes aes[1];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
if (aes == NULL)
|
||||||
|
return MEMORY_E;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ret = wc_AesSetKey(aes, key, keySz, iv, AES_ENCRYPTION);
|
||||||
|
if (ret == 0)
|
||||||
|
ret = wc_AesCbcEncrypt(aes, out, in, inSz);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
|
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif /* !NO_AES */
|
||||||
|
|
@@ -133,12 +133,6 @@ WOLFSSL_API int wc_AesCbcEncrypt(Aes* aes, byte* out,
|
|||||||
const byte* in, word32 sz);
|
const byte* in, word32 sz);
|
||||||
WOLFSSL_API int wc_AesCbcDecrypt(Aes* aes, byte* out,
|
WOLFSSL_API int wc_AesCbcDecrypt(Aes* aes, byte* out,
|
||||||
const byte* in, word32 sz);
|
const byte* in, word32 sz);
|
||||||
WOLFSSL_API int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
|
|
||||||
const byte* key, word32 keySz,
|
|
||||||
const byte* iv);
|
|
||||||
WOLFSSL_API int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
|
|
||||||
const byte* key, word32 keySz,
|
|
||||||
const byte* iv);
|
|
||||||
|
|
||||||
/* AES-CTR */
|
/* AES-CTR */
|
||||||
#ifdef WOLFSSL_AES_COUNTER
|
#ifdef WOLFSSL_AES_COUNTER
|
||||||
|
@@ -29,6 +29,7 @@ nobase_include_HEADERS+= \
|
|||||||
wolfssl/wolfcrypt/md5.h \
|
wolfssl/wolfcrypt/md5.h \
|
||||||
wolfssl/wolfcrypt/misc.h \
|
wolfssl/wolfcrypt/misc.h \
|
||||||
wolfssl/wolfcrypt/pkcs7.h \
|
wolfssl/wolfcrypt/pkcs7.h \
|
||||||
|
wolfssl/wolfcrypt/wc_encrypt.h \
|
||||||
wolfssl/wolfcrypt/wc_port.h \
|
wolfssl/wolfcrypt/wc_port.h \
|
||||||
wolfssl/wolfcrypt/pwdbased.h \
|
wolfssl/wolfcrypt/pwdbased.h \
|
||||||
wolfssl/wolfcrypt/rabbit.h \
|
wolfssl/wolfcrypt/rabbit.h \
|
||||||
|
47
wolfssl/wolfcrypt/wc_encrypt.h
Normal file
47
wolfssl/wolfcrypt/wc_encrypt.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/* wc_encrypt.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2015 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_ENCRYPT_H
|
||||||
|
#define WOLF_CRYPT_ENCRYPT_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_AES
|
||||||
|
WOLFSSL_API int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
|
||||||
|
const byte* key, word32 keySz,
|
||||||
|
const byte* iv);
|
||||||
|
WOLFSSL_API int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
|
||||||
|
const byte* key, word32 keySz,
|
||||||
|
const byte* iv);
|
||||||
|
#endif /* NO_AES */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_ENCRYPT_H */
|
||||||
|
|
Reference in New Issue
Block a user