Skip to content

Updating Crypto from cyassl to wolfssl, updating headers #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions crypto/3des/3des-file-encrypt.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
/* 3des-file-encrypt.c
*
* Copyright (C) 2006-2014 wolfSSL Inc.
* This file is part of CyaSSL.
* Copyright (C) 2006-2015 wolfSSL Inc.
*
* CyaSSL is free software; you can redistribute it and/or modify
* 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.
*
* 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.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <cyassl/options.h>
#include <cyassl/ctaocrypt/des3.h>
#include <cyassl/ctaocrypt/sha256.h>
#include <cyassl/ctaocrypt/random.h>
#include <cyassl/ctaocrypt/pwdbased.h>
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/des3.h>
#include <wolfssl/wolfcrypt/sha256.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/pwdbased.h>

#define DES3_BLOCK_SIZE 24 /* size of encryption blocks */
#define SALT_SIZE 8
Expand All @@ -37,15 +38,15 @@ int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad)
{
int ret;

ret = RNG_GenerateBlock(rng, salt, SALT_SIZE);
ret = wc_RNG_GenerateBlock(rng, salt, SALT_SIZE);
if (ret != 0)
return -1020;

if (pad == 0) /* sets first value of salt to check if the */
salt[0] = 0; /* message is padded */

/* stretches key */
ret = PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
ret = wc_PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
size, SHA256);
if (ret != 0)
return -1030;
Expand Down Expand Up @@ -84,7 +85,7 @@ int Des3Encrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
input = malloc(length);
output = malloc(length);

ret = InitRng(&rng);
ret = wc_InitRng(&rng);
if (ret != 0) {
printf("Failed to initialize random number generator\n");
return -1030;
Expand All @@ -101,7 +102,7 @@ int Des3Encrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
input[i] = padCounter;
}

ret = RNG_GenerateBlock(&rng, iv, DES3_BLOCK_SIZE);
ret = wc_RNG_GenerateBlock(&rng, iv, DES3_BLOCK_SIZE);
if (ret != 0)
return -1020;

Expand All @@ -111,12 +112,12 @@ int Des3Encrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
return -1040;

/* sets key */
ret = Des3_SetKey(des3, key, iv, DES_ENCRYPTION);
ret = wc_Des3_SetKey(des3, key, iv, DES_ENCRYPTION);
if (ret != 0)
return -1001;

/* encrypts the message to the ouput based on input length + padding */
ret = Des3_CbcEncrypt(des3, output, input, length);
ret = wc_Des3_CbcEncrypt(des3, output, input, length);
if (ret != 0)
return -1005;

Expand Down Expand Up @@ -162,7 +163,7 @@ int Des3Decrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
input = malloc(aSize);
output = malloc(aSize);

InitRng(&rng);
wc_InitRng(&rng);

/* reads from inFile and wrties whatever is there to the input array */
ret = fread(input, 1, length, inFile);
Expand All @@ -180,13 +181,13 @@ int Des3Decrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
}

/* replicates old key if keys match */
ret = PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
ret = wc_PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
size, SHA256);
if (ret != 0)
return -1050;

/* sets key */
ret = Des3_SetKey(des3, key, iv, DES_DECRYPTION);
ret = wc_Des3_SetKey(des3, key, iv, DES_DECRYPTION);
if (ret != 0)
return -1002;

Expand All @@ -197,7 +198,7 @@ int Des3Decrypt(Des3* des3, byte* key, int size, FILE* inFile, FILE* outFile)
input[i] = input[i + (DES3_BLOCK_SIZE + SALT_SIZE)];
}
/* decrypts the message to output based on input length + padding */
ret = Des3_CbcDecrypt(des3, output, input, length);
ret = wc_Des3_CbcDecrypt(des3, output, input, length);
if (ret != 0)
return -1006;

Expand Down
41 changes: 21 additions & 20 deletions crypto/aes/aes-file-encrypt.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
/* aes-file-encrypt.c
*
* Copyright (C) 2006-2014 wolfSSL Inc.
* This file is part of CyaSSL.
* Copyright (C) 2006-2015 wolfSSL Inc.
*
* CyaSSL is free software; you can redistribute it and/or modify
* 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.
*
* 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.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <cyassl/options.h>
#include <cyassl/ctaocrypt/aes.h>
#include <cyassl/ctaocrypt/sha256.h>
#include <cyassl/ctaocrypt/random.h>
#include <cyassl/ctaocrypt/pwdbased.h>
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/aes.h>
#include <wolfssl/wolfcrypt/sha256.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/pwdbased.h>

#define SALT_SIZE 8

Expand All @@ -36,15 +37,15 @@ int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad)
{
int ret;

ret = RNG_GenerateBlock(rng, salt, SALT_SIZE);
ret = wc_RNG_GenerateBlock(rng, salt, SALT_SIZE);
if (ret != 0)
return -1020;

if (pad == 0)
salt[0] = 0;

/* stretches key */
ret = PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
ret = wc_PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
size, SHA256);
if (ret != 0)
return -1030;
Expand Down Expand Up @@ -83,7 +84,7 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
input = malloc(length);
output = malloc(length);

ret = InitRng(&rng);
ret = wc_InitRng(&rng);
if (ret != 0) {
printf("Failed to initialize random number generator\n");
return -1030;
Expand All @@ -100,7 +101,7 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
input[i] = padCounter;
}

ret = RNG_GenerateBlock(&rng, iv, AES_BLOCK_SIZE);
ret = wc_RNG_GenerateBlock(&rng, iv, AES_BLOCK_SIZE);
if (ret != 0)
return -1020;

Expand All @@ -110,12 +111,12 @@ int AesEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
return -1040;

/* sets key */
ret = AesSetKey(aes, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
ret = wc_AesSetKey(aes, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
if (ret != 0)
return -1001;

/* encrypts the message to the ouput based on input length + padding */
ret = AesCbcEncrypt(aes, output, input, length);
ret = wc_AesCbcEncrypt(aes, output, input, length);
if (ret != 0)
return -1005;

Expand Down Expand Up @@ -161,7 +162,7 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
input = malloc(aSize);
output = malloc(aSize);

InitRng(&rng);
wc_InitRng(&rng);

/* reads from inFile and wrties whatever is there to the input array */
ret = fread(input, 1, length, inFile);
Expand All @@ -179,13 +180,13 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
}

/* replicates old key if keys match */
ret = PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
ret = wc_PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
size, SHA256);
if (ret != 0)
return -1050;

/* sets key */
ret = AesSetKey(aes, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION);
ret = wc_AesSetKey(aes, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION);
if (ret != 0)
return -1002;

Expand All @@ -196,7 +197,7 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
input[i] = input[i + (AES_BLOCK_SIZE + SALT_SIZE)];
}
/* decrypts the message to output based on input length + padding*/
ret = AesCbcDecrypt(aes, output, input, length);
ret = wc_AesCbcDecrypt(aes, output, input, length);
if (ret != 0)
return -1006;

Expand Down
41 changes: 21 additions & 20 deletions crypto/camellia/camellia-encrypt.c
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
/* camellia-encrypt.c
*
* Copyright (C) 2006-2014 wolfSSL Inc.
* This file is part of CyaSSL.
* Copyright (C) 2006-2015 wolfSSL Inc.
*
* CyaSSL is free software; you can redistribute it and/or modify
* 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.
*
* 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.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <cyassl/options.h>
#include <cyassl/ctaocrypt/sha256.h>
#include <cyassl/ctaocrypt/random.h>
#include <cyassl/ctaocrypt/pwdbased.h>
#include <cyassl/ctaocrypt/camellia.h>
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/sha256.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/pwdbased.h>
#include <wolfssl/wolfcrypt/camellia.h>

#define SALT_SIZE 8

Expand All @@ -36,15 +37,15 @@ int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad)
{
int ret;

ret = RNG_GenerateBlock(rng, salt, SALT_SIZE-1);
ret = wc_RNG_GenerateBlock(rng, salt, SALT_SIZE-1);
if (ret != 0)
return -1020;

if (pad == 0) /* sets first value of salt to check if the */
salt[0] = 0; /* message is padded */

/* stretches key */
ret = PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
ret = wc_PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
size, SHA256);
if (ret != 0)
return -1030;
Expand Down Expand Up @@ -84,7 +85,7 @@ int CamelliaEncrypt(Camellia* cam, byte* key, int size, FILE* inFile,
input = malloc(length);
output = malloc(length);

ret = InitRng(&rng);
ret = wc_InitRng(&rng);
if (ret != 0) {
printf("Failed to initialize random number generator\n");
return -1030;
Expand All @@ -101,7 +102,7 @@ int CamelliaEncrypt(Camellia* cam, byte* key, int size, FILE* inFile,
input[i] = padCounter;
}

ret = RNG_GenerateBlock(&rng, iv, CAMELLIA_BLOCK_SIZE);
ret = wc_RNG_GenerateBlock(&rng, iv, CAMELLIA_BLOCK_SIZE);
if (ret != 0)
return -1020;

Expand All @@ -111,12 +112,12 @@ int CamelliaEncrypt(Camellia* cam, byte* key, int size, FILE* inFile,
return -1040;

/* sets key */
ret = CamelliaSetKey(cam, key, CAMELLIA_BLOCK_SIZE, iv);
ret = wc_CamelliaSetKey(cam, key, CAMELLIA_BLOCK_SIZE, iv);
if (ret != 0)
return -1001;

/* encrypts the message to the ouput based on input length + padding */
CamelliaCbcEncrypt(cam, output, input, length);
wc_CamelliaCbcEncrypt(cam, output, input, length);

/* writes to outFile */
fwrite(salt, 1, SALT_SIZE, outFile);
Expand Down Expand Up @@ -161,7 +162,7 @@ int CamelliaDecrypt(Camellia* cam, byte* key, int size, FILE* inFile,
input = malloc(aSize);
output = malloc(aSize);

InitRng(&rng);
wc_InitRng(&rng);

/* reads from inFile and wrties whatever is there to the input array */
ret = fread(input, 1, length, inFile);
Expand All @@ -179,13 +180,13 @@ int CamelliaDecrypt(Camellia* cam, byte* key, int size, FILE* inFile,
}

/* replicates old key if keys match */
ret = PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
ret = wc_PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
size, SHA256);
if (ret != 0)
return -1050;

/* sets key */
ret = CamelliaSetKey(cam, key, CAMELLIA_BLOCK_SIZE, iv);
ret = wc_CamelliaSetKey(cam, key, CAMELLIA_BLOCK_SIZE, iv);
if (ret != 0)
return -1002;

Expand All @@ -196,7 +197,7 @@ int CamelliaDecrypt(Camellia* cam, byte* key, int size, FILE* inFile,
input[i] = input[i + (CAMELLIA_BLOCK_SIZE + SALT_SIZE)];
}
/* decrypts the message to output based on input length + padding */
CamelliaCbcDecrypt(cam, output, input, length);
wc_CamelliaCbcDecrypt(cam, output, input, length);

if (salt[0] != 0) {
/* reduces length based on number of padded elements */
Expand Down