From 0d4a65cd6f2fdc6ebcbe82e9f1e0d6995100c9bb Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Tue, 30 Dec 2014 14:41:49 -0700 Subject: [PATCH] pwdbased updated --- wolfcrypt/src/pwdbased.c | 50 ++++++++++++++++++------------------ wolfssl/wolfcrypt/pwdbased.h | 23 +++++++++-------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/wolfcrypt/src/pwdbased.c b/wolfcrypt/src/pwdbased.c index ca96a40f1..6e08d1436 100644 --- a/wolfcrypt/src/pwdbased.c +++ b/wolfcrypt/src/pwdbased.c @@ -23,11 +23,11 @@ #include #endif -#include +#include #ifndef NO_PWDBASED -#ifdef CYASSL_PIC32MZ_HASH +#ifdef WOLFSSL_PIC32MZ_HASH #define InitMd5 InitMd5_sw #define Md5Update Md5Update_sw @@ -43,18 +43,18 @@ #endif -#include -#include -#include -#include -#if defined(CYASSL_SHA512) || defined(CYASSL_SHA384) - #include +#include +#include +#include +#include +#if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384) + #include #endif #ifdef NO_INLINE - #include + #include #else - #include + #include #endif @@ -68,7 +68,7 @@ #endif /* min */ -int PBKDF1(byte* output, const byte* passwd, int pLen, const byte* salt, +int wc_PBKDF1(byte* output, const byte* passwd, int pLen, const byte* salt, int sLen, int iterations, int kLen, int hashType) { Md5 md5; @@ -117,14 +117,14 @@ int PBKDF1(byte* output, const byte* passwd, int pLen, const byte* salt, } -int PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt, +int wc_PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt, int sLen, int iterations, int kLen, int hashType) { word32 i = 1; int hLen; int j, ret; Hmac hmac; -#ifdef CYASSL_SMALL_STACK +#ifdef WOLFSSL_SMALL_STACK byte* buffer; #else byte buffer[MAX_DIGEST_SIZE]; @@ -141,7 +141,7 @@ int PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt, hLen = SHA256_DIGEST_SIZE; } #endif -#ifdef CYASSL_SHA512 +#ifdef WOLFSSL_SHA512 else if (hashType == SHA512) { hLen = SHA512_DIGEST_SIZE; } @@ -149,7 +149,7 @@ int PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt, else return BAD_FUNC_ARG; -#ifdef CYASSL_SMALL_STACK +#ifdef WOLFSSL_SMALL_STACK buffer = (byte*)XMALLOC(MAX_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (buffer == NULL) return MEMORY_E; @@ -205,14 +205,14 @@ int PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt, } } -#ifdef CYASSL_SMALL_STACK +#ifdef WOLFSSL_SMALL_STACK XFREE(buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; } -#ifdef CYASSL_SHA512 +#ifdef WOLFSSL_SHA512 #define PBKDF_DIGEST_SIZE SHA512_BLOCK_SIZE #elif !defined(NO_SHA256) #define PBKDF_DIGEST_SIZE SHA256_BLOCK_SIZE @@ -220,7 +220,7 @@ int PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt, #define PBKDF_DIGEST_SIZE SHA_DIGEST_SIZE #endif -int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, +int wc_PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, int saltLen, int iterations, int kLen, int hashType, int id) { /* all in bytes instead of bits */ @@ -229,14 +229,14 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, int ret = 0; int i; byte *D, *S, *P, *I; -#ifdef CYASSL_SMALL_STACK +#ifdef WOLFSSL_SMALL_STACK byte staticBuffer[1]; /* force dynamic usage */ #else byte staticBuffer[1024]; #endif byte* buffer = staticBuffer; -#ifdef CYASSL_SMALL_STACK +#ifdef WOLFSSL_SMALL_STACK byte* Ai; byte* B; #else @@ -261,7 +261,7 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, u = SHA256_DIGEST_SIZE; } #endif -#ifdef CYASSL_SHA512 +#ifdef WOLFSSL_SHA512 else if (hashType == SHA512) { v = SHA512_BLOCK_SIZE; u = SHA512_DIGEST_SIZE; @@ -270,7 +270,7 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, else return BAD_FUNC_ARG; -#ifdef CYASSL_SMALL_STACK +#ifdef WOLFSSL_SMALL_STACK Ai = (byte*)XMALLOC(PBKDF_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (Ai == NULL) return MEMORY_E; @@ -295,7 +295,7 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, if (totalLen > sizeof(staticBuffer)) { buffer = (byte*)XMALLOC(totalLen, 0, DYNAMIC_TYPE_KEY); if (buffer == NULL) { -#ifdef CYASSL_SMALL_STACK +#ifdef WOLFSSL_SMALL_STACK XFREE(Ai, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(B, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif @@ -373,7 +373,7 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, } } #endif -#ifdef CYASSL_SHA512 +#ifdef WOLFSSL_SHA512 else if (hashType == SHA512) { Sha512 sha512; @@ -460,7 +460,7 @@ int PKCS12_PBKDF(byte* output, const byte* passwd, int passLen,const byte* salt, if (dynamic) XFREE(buffer, 0, DYNAMIC_TYPE_KEY); -#ifdef CYASSL_SMALL_STACK +#ifdef WOLFSSL_SMALL_STACK XFREE(Ai, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(B, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif diff --git a/wolfssl/wolfcrypt/pwdbased.h b/wolfssl/wolfcrypt/pwdbased.h index 04ea330a8..505544a6e 100644 --- a/wolfssl/wolfcrypt/pwdbased.h +++ b/wolfssl/wolfcrypt/pwdbased.h @@ -2,14 +2,14 @@ * * Copyright (C) 2006-2014 wolfSSL Inc. * - * This file is part of CyaSSL. + * This file is part of wolfSSL. (formerly known as CyaSSL) * - * CyaSSL is free software; you can redistribute it and/or modify + * 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. * - * CyaSSL is distributed in the hope that it will be useful, + * 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. @@ -22,25 +22,26 @@ #ifndef NO_PWDBASED -#ifndef CTAO_CRYPT_PWDBASED_H -#define CTAO_CRYPT_PWDBASED_H +#ifndef WOLF_CRYPT_PWDBASED_H +#define WOLF_CRYPT_PWDBASED_H #include -#include /* for hash type */ -#include + +/* included for fips @wc_fips */ +#include #ifdef __cplusplus extern "C" { #endif -CYASSL_API int PBKDF1(byte* output, const byte* passwd, int pLen, +WOLFSSL_API int wc_PBKDF1(byte* output, const byte* passwd, int pLen, const byte* salt, int sLen, int iterations, int kLen, int hashType); -CYASSL_API int PBKDF2(byte* output, const byte* passwd, int pLen, +WOLFSSL_API int wc_PBKDF2(byte* output, const byte* passwd, int pLen, const byte* salt, int sLen, int iterations, int kLen, int hashType); -CYASSL_API int PKCS12_PBKDF(byte* output, const byte* passwd, int pLen, +WOLFSSL_API int wc_PKCS12_PBKDF(byte* output, const byte* passwd, int pLen, const byte* salt, int sLen, int iterations, int kLen, int hashType, int purpose); @@ -49,5 +50,5 @@ CYASSL_API int PKCS12_PBKDF(byte* output, const byte* passwd, int pLen, } /* extern "C" */ #endif -#endif /* CTAO_CRYPT_PWDBASED_H */ +#endif /* WOLF_CRYPT_PWDBASED_H */ #endif /* NO_PWDBASED */