아래의 해당 프로그램의 경우 iv 값이 설정이 되어 있지 않기 때문에
동일값이
/*** sha256_test.c ***/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main(int argc, char *argv[])
{
unsigned char plain_data[256];
unsigned char hash_data[256];
int plain_data_len;
int i;
memset(plain_data, 0x00, sizeof(plain_data));
memset(hash_data, 0x00, sizeof(hash_data));
sprintf(plain_data, "1234");
plain_data_len = strlen(plain_data);
sha256(plain_data, plain_data_len, hash_data);
fprintf(stdout, "plain\n");
fprintf(stdout, "%.*s\n", plain_data_len, plain_data);
fprintf(stdout, "sha256_data\n");
for( i = 0; i < strlen(hash_data); i++ ) {
fprintf(stdout, "%02x", hash_data[i]);
}
fprintf(stdout, "\n");
return 1;
}
int sha256(unsigned char *plain_data, int plain_data_len, unsigned char *hash_data)
{
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, plain_data, plain_data_len);
SHA256_Final(hash_data, &sha256);
return 1;
}
컴파일)
gcc -lcrypto sha256_test.c -o sha256_test
실행결과)
$ sha256_test
plain
1234
sha256_data
03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4
sha256실행시 결과값)
plain
0
sha256_data
5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9
plain
0000
sha256_data
9af15b336e6a9619928537df30b2e6a2376569fcf9d7e773eccede65606529a0
plain
1111
sha256_data
0ffe1abd1a08215353c233d6e009613e95eec4253832a761af28ff37ac5a150c
plain
9999
sha256_data
888df25ae35772424a560c7152a1de794440e0ea5cfee62828333a456a506e05
plain
1234567890
sha256_data
c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646
plain
ABCD
sha256_data
e12e115acf4552b2568b55e93cbd39394c4ef81c82447fafc997882a02d23677
plain
abcd
sha256_data
88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589