-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifykey.c
93 lines (76 loc) · 3.02 KB
/
verifykey.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* this is a block of example code I used to test the system early on no longer in use */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include "hmac_sha2.h"
#include <ctype.h>
#define FNV_PRIME_32 16777619
#define MASK_24 (((uint32_t)1<<24)-1) /* i.e., (u_int32_t)0xffffff */
uint32_t fnv_hasher(uint8_t *str)
{
uint32_t hval = 0;
/*
* FNV-1 hash each octet in the buffer
*/
int i = 0;
for (i = 0; i < 32; i++) {
/* multiply by the 32 bit FNV magic prime mod 2^32 */
hval *= FNV_PRIME_32;
/* xor the bottom with the current octet */
hval ^= (uint32_t)str[i];
}
/* return our new hash value */
return hval;
}
static void display_hex(unsigned length, uint8_t *data)
{
unsigned i;
printf("sha sum is:");
for (i = 0; i<length; i++)
printf("%02x", data[i]);
printf("\n");
}
int
main(int argc, char **argv)
{
// struct hmac_sha256_ctx sha256;
uint8_t digest[SHA256_DIGEST_SIZE];
uint8_t ihatebuffers[4] = {0};
uint32_t fnv_hash,fnv_hash2;
uint32_t time = 1296579900;
memset(digest, 0, sizeof(digest));
uint8_t hmacKey5[]={
0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,
0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,
0x2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2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,0x2a,
0x2a,0x2a,0x2a,0x2a,0x2a
};
ihatebuffers[3] = (uint8_t)time;
ihatebuffers[2] = (uint8_t)(time >> 8);
ihatebuffers[1] = (uint8_t)(time >> 16);
ihatebuffers[0] = (uint8_t)(time >> 24);
hmac_sha256(hmacKey5, 256, ihatebuffers,4, digest, SHA256_DIGEST_SIZE);
// ihatebuffers[3] = 'f';
// ihatebuffers[2] = 'd';
// ihatebuffers[1] = 's';
// ihatebuffers[0] = 'a';
printf("date: %02X\n", time);
display_hex(SHA256_DIGEST_SIZE, digest);
fnv_hash = fnv_hasher(digest);
printf("32 byte hash:%02X\n", fnv_hash);
fnv_hash2 = (fnv_hash>>24) ^ (fnv_hash & MASK_24);
printf("24 byte hash:%02X\n", fnv_hash2);
return EXIT_SUCCESS;
}