Merge pull request #29 from dgarske/clu_base64

wolfCLU base64 support
pull/31/head
Kaleb Himes 2016-11-17 13:39:08 -07:00 committed by GitHub
commit cde614c4aa
5 changed files with 150 additions and 72 deletions

View File

@ -19,6 +19,9 @@ recipient of the encrypted file.
`--enable-opensslextra` provides utility for a hex to binary conversion of
hexidecimal values.
`--enable-base64encode` enables Base64 encoding (not on by default)
Additional features that can be included when configuring wolfssl for
encryption or decryption are:
@ -44,4 +47,26 @@ Now you should be able to use the wolfssl command line tool. To verify type:
If everything worked, you should see the wolfssl help page.
Thank you and have fun!
## Examples
### Base64
#### Encode
```
./wolfssl -hash base64enc -in README.md > README_encoded.md
```
#### Decode
```
./wolfssl -hash base64dec -in README_encoded.md
```
## Contacts
Please contact support@wolfssl.com with any questions or comments
## License
Copyright (c) 2006-2015 wolfSSL Inc.

View File

@ -65,6 +65,8 @@
#include <wolfssl/wolfcrypt/camellia.h>
#endif
#include <wolfssl/wolfcrypt/coding.h>
#ifndef UTIL_H_INCLUDED
#define UTIL_H_INCLUDED

View File

@ -40,9 +40,7 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
int i = 0; /* loop variable */
int ret = -1; /* return variable */
int length; /* length of hash */
output = malloc(size);
XMEMSET(output, 0, size);
int outputAsHexString = 1;
/* opens input file */
inFile = fopen(in, "rb");
@ -76,6 +74,15 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
ret = (int) fread(input, 1, length, inFile);
fclose(inFile);
}
/* if size not provided then use input length */
if (size == 0) {
size = length * 4;
}
output = malloc(size);
XMEMSET(output, 0, size);
/* hashes using accepted algorithm */
#ifndef NO_MD5
if (strcmp(alg, "md5") == 0) {
@ -109,6 +116,20 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
ret = wc_Blake2bFinal(&hash, output, size);
}
#endif
#ifndef NO_CODING
#ifdef WOLFSSL_BASE64_ENCODE
else if (strcmp(alg, "base64enc") == 0) {
ret = Base64_Encode(input, length, output, (word32*)&size);
outputAsHexString = 0;
}
#endif /* WOLFSSL_BASE64_ENCODE */
else if (strcmp(alg, "base64dec") == 0) {
ret = Base64_Decode(input, length, output, (word32*)&size);
outputAsHexString = 0;
}
#endif /* !NO_CODING */
if (ret == 0) {
/* if no errors so far */
if (out != NULL) {
@ -118,7 +139,10 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
/* if outFile exists */
for (i = 0; i < size; i++) {
/* writes hashed output to outFile */
if (outputAsHexString)
fprintf(outFile, "%02x", output[i]);
else
fprintf(outFile, "%c", output[i]);
}
fclose(outFile);
}
@ -127,7 +151,10 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
/* if no output file */
for (i = 0; i < size; i++) {
/* write hashed output to terminal */
if (outputAsHexString)
printf("%02x", output[i]);
else
printf("%c", output[i]);
}
printf("\n");
}

View File

@ -48,6 +48,12 @@ int wolfsslHashSetup(int argc, char** argv)
#endif
#ifdef HAVE_BLAKE2
, "blake2b"
#endif
#ifndef NO_CODING
#ifdef WOLFSSL_BASE64_ENCODE
, "base64enc"
#endif
, "base64dec"
#endif
};
@ -146,7 +152,7 @@ int wolfsslHashSetup(int argc, char** argv)
#endif
/* hashing function */
wolfsslHash(in, out, alg, size);
ret = wolfsslHash(in, out, alg, size);
free(in);

View File

@ -68,6 +68,7 @@ int i = 0; /* loop variable */
void wolfsslVerboseHelp()
{
printf("\nwolfssl Command Line Utility version %3.1f\n\n", VERSION);
/* hash options */
const char* algsenc[] = { /* list of acceptable algorithms */
#ifndef NO_MD5
@ -87,6 +88,12 @@ void wolfsslVerboseHelp()
#endif
#ifdef HAVE_BLAKE2
,"blake2b"
#endif
#ifndef NO_CODING
#ifdef WOLFSSL_BASE64_ENCODE
,"base64enc"
#endif
,"base64dec"
#endif
};
@ -123,6 +130,7 @@ void wolfsslVerboseHelp()
, "blake2b"
#endif
};
wolfsslHelp();
printf("Available En/De crypt Algorithms with current configure "
@ -235,6 +243,12 @@ void wolfsslHashHelp()
#endif
#ifdef HAVE_BLAKE2
,"blake2b"
#endif
#ifndef NO_CODING
#ifdef WOLFSSL_BASE64_ENCODE
,"base64enc"
#endif
,"base64dec"
#endif
};
@ -255,6 +269,7 @@ void wolfsslHashHelp()
void wolfsslBenchHelp()
{
printf("\n");
/* benchmark options */
const char* algsother[] = { /* list of acceptable algorithms */
#ifndef NO_AES
@ -288,6 +303,7 @@ void wolfsslBenchHelp()
, "blake2b"
#endif
};
printf("\nAvailable tests: (-a to test all)\n");
printf("Available tests with current configure settings:\n");
for(i = 0; i < (int) sizeof(algsother)/(int) sizeof(algsother[0]); i++) {
@ -312,6 +328,7 @@ int wolfsslGetAlgo(char* name, char** alg, char** mode, int* size)
int nameCheck = 0; /* check for acceptable name */
int modeCheck = 0; /* check for acceptable mode */
char* sz = 0; /* key size provided */
const char* acceptAlgs[] = { /* list of acceptable algorithms */
#ifndef NO_AES
"aes"
@ -323,6 +340,7 @@ int wolfsslGetAlgo(char* name, char** alg, char** mode, int* size)
, "camellia"
#endif
};
const char* acceptMode[] = {"cbc"
#ifdef WOLFSSL_AES_COUNTER
, "ctr"