-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcrc32.c
More file actions
35 lines (30 loc) · 780 Bytes
/
crc32.c
File metadata and controls
35 lines (30 loc) · 780 Bytes
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
#include "crc32.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
#include "common.h"
#include "jtr_crc32.h"
/*
* 功能:单向函数 hello_crc32
* 输入:1. input :输入消息
* 2. output:输出结果
*/
void hello_crc32(uint8_t *input, uint32_t inputLen, uint8_t *output) {
/**
* $hash[0:31] = sha256($input)
* $output[0:31] = crc32($hash[0:31]), crc by word
**/
uint8_t sha256Digest[SHA256_DIGEST_LENGTH];
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, input, inputLen);
SHA256_Final(sha256Digest, &ctx);
CRC32_t crc;
for (uint32_t i = 0; i < SHA256_DIGEST_LENGTH; i += 4) {
CRC32_Init(&crc);
CRC32_Update(&crc, &sha256Digest[i], 4);
CRC32_Final(&output[i], crc);
}
}