forked from oshrat/csd162ass2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate_sha256.c
58 lines (42 loc) · 1022 Bytes
/
calculate_sha256.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//compile with -lcrypto
#include <openssl/sha.h>
#include <stdio.h>
int calculate_sha256(unsigned char* temp){
SHA256_CTX sha256;
SHA256_Init(&sha256);
printf ("%s", temp); //optional
SHA256_Update(&sha256, temp, 4);
SHA256_Final(temp, &sha256);
printf("%p\n", temp); //optional
// printf("%u\n", (unsigned int)(*temp)); //optional
// printf("%c\n", temp); //optional
return 0;
}
//C++ example #1:
/*
string sha256(const string str)
{
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str.c_str(), str.size());
SHA256_Final(hash, &sha256);
stringstream ss;
for(int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
ss << hex << setw(2) << setfill('0') << (int)hash[i];
}
return ss.str();
}
int main()
{
cout << sha256("test") << endl;
cout << sha256("test2") << endl;
return 0;
}
*/
int main(){
unsigned char temp[32] = "hi!\n";
calculate_sha256(temp);
return 0;
}