* Added AES and AES-CTR modules. AES-CTR conforms to the same counter mode used with AES in *OpenSSL*. * All algorithms now work on Big-Endian architectures. * Now uses CMake for building rather than make files and Visual Studio projects. CMake will generate whatever system is required. * Input function parameters are now marked `const` * File names have been changed to have the prefix `CryptLib_` rather than `Lib`. * Various formatting changes to the files.
62 lines
2.0 KiB
C
62 lines
2.0 KiB
C
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Sha256String
|
|
//
|
|
// Outputs SHA256 hash of a string specified on command line. Hash is output in hex
|
|
//
|
|
// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// IMPORTS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include "CryptLib_Sha256.h"
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// FUNCTIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// main
|
|
//
|
|
// Program entry point
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int
|
|
main
|
|
(
|
|
int ArgC,
|
|
char** ArgV
|
|
)
|
|
{
|
|
char* string;
|
|
Sha256Context sha256Context;
|
|
SHA256_HASH sha256Hash;
|
|
uint16_t i;
|
|
|
|
if( 2 != ArgC )
|
|
{
|
|
printf(
|
|
"Syntax\n"
|
|
" Sha256String <String>\n" );
|
|
return 1;
|
|
}
|
|
|
|
string = ArgV[1];
|
|
|
|
Sha256Initialise( &sha256Context );
|
|
Sha256Update( &sha256Context, (unsigned char*)string, (uint32_t)strlen(string) );
|
|
Sha256Finalise( &sha256Context, &sha256Hash );
|
|
|
|
for( i=0; i<sizeof(sha256Hash); i++ )
|
|
{
|
|
printf( "%2.2x", sha256Hash.bytes[i] );
|
|
}
|
|
printf( "\n" );
|
|
|
|
return 0;
|
|
}
|