-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.h
More file actions
74 lines (60 loc) · 1.68 KB
/
Copy pathcheck.h
File metadata and controls
74 lines (60 loc) · 1.68 KB
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
#pragma once
/**
* @author smallfoot47
* @file check.cpp
* @brief Implementation of state-bound crc instance
*/
/***** Includes *****/
#include <stdint.h>
#include "mxc_device.h"
#include "nvic_table.h"
#include "board.h"
#include "crc.h"
#include "dma.h"
/***** Definitions *****/
#define POLY 0xEDB88320
#define CHANNELS 8
#define CHANNEL_SIZE 16
/***** Classes *****/
uint32_t CRC_RESULTS[CHANNELS];
void CHECKER_INIT() {
MXC_CRC_Init();
MXC_CRC_SetPoly(POLY);
for (short i = 0; i < CHANNELS; ++i)
CRC_RESULTS[i] = 0u;
}
const uint32_t CRC_COMPUTE(uint32_t* memory) {
mxc_crc_req_t crc_req = {
memory,
CHANNEL_SIZE,
0
};
MXC_CRC_Compute(&crc_req);
return crc_req.resultCRC;
}
void CHECKER_REMEMBER_CHANNEL(uint32_t* channel_location) {
CRC_RESULTS[((uint32_t)channel_location / CHANNEL_SIZE) % CHANNELS] = CRC_COMPUTE(channel_location);
}
const bool CHECKER_VERIFY_CHANNEL(uint32_t* channel_location) {
return CRC_COMPUTE(channel_location) == CRC_RESULTS[((uint32_t)channel_location / CHANNEL_SIZE) % CHANNELS];
}
void CHECKER_END() {
MXC_CRC_Shutdown();
}
/*
Usage:
CHECKER_INIT(); // invoked initially
...
// assuming channel1 stores channel 1's data
CHECKER_REMEMBER_CHANNEL(&channel1);
...
// channels talk
...
// need to verify integrity of channel 1's data
if (! CHECKER_VERIFY_CHANNEL(&channel1)) {
// channel 1 compromised!
}
...
CHECKER_END(); // called when channels are no longer needed
*/
// *****************************************************************************