add header guards, move declarations to source file
This commit is contained in:
parent
4a0ff55773
commit
3a420d5c6c
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef TOTP_H_
|
||||||
|
#define TOTP_H_
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
|
||||||
@ -6,3 +9,5 @@ void setTimezone(uint8_t timezone);
|
|||||||
uint32_t getCodeFromTimestamp(uint32_t timeStamp);
|
uint32_t getCodeFromTimestamp(uint32_t timeStamp);
|
||||||
uint32_t getCodeFromTimeStruct(struct tm time);
|
uint32_t getCodeFromTimeStruct(struct tm time);
|
||||||
uint32_t getCodeFromSteps(uint32_t steps);
|
uint32_t getCodeFromSteps(uint32_t steps);
|
||||||
|
|
||||||
|
#endif // TOTP_H_
|
||||||
|
@ -14,6 +14,20 @@ uint8_t sha1InitState[] = {
|
|||||||
0xf0,0xe1,0xd2,0xc3 // H4
|
0xf0,0xe1,0xd2,0xc3 // H4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
union _buffer {
|
||||||
|
uint8_t b[BLOCK_LENGTH];
|
||||||
|
uint32_t w[BLOCK_LENGTH/4];
|
||||||
|
} buffer;
|
||||||
|
union _state {
|
||||||
|
uint8_t b[HASH_LENGTH];
|
||||||
|
uint32_t w[HASH_LENGTH/4];
|
||||||
|
} state;
|
||||||
|
|
||||||
|
uint8_t bufferOffset;
|
||||||
|
uint32_t byteCount;
|
||||||
|
uint8_t keyBuffer[BLOCK_LENGTH];
|
||||||
|
uint8_t innerHash[HASH_LENGTH];
|
||||||
|
|
||||||
void init(void) {
|
void init(void) {
|
||||||
memcpy(state.b,sha1InitState,HASH_LENGTH);
|
memcpy(state.b,sha1InitState,HASH_LENGTH);
|
||||||
byteCount = 0;
|
byteCount = 0;
|
||||||
@ -84,7 +98,7 @@ void writeArray(uint8_t *buffer, uint8_t size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pad() {
|
void pad() {
|
||||||
// Implement SHA-1 padding (fips180-2 <20>˜5.1.1)
|
// Implement SHA-1 padding (fips180-2 <20><EFBFBD>5.1.1)
|
||||||
|
|
||||||
// Pad with 0x80 followed by 0x00 until the end of the block
|
// Pad with 0x80 followed by 0x00 until the end of the block
|
||||||
addUncounted(0x80);
|
addUncounted(0x80);
|
||||||
|
@ -1,25 +1,16 @@
|
|||||||
|
#ifndef SHA1_H_
|
||||||
|
#define SHA1_H_
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#define HASH_LENGTH 20
|
#define HASH_LENGTH 20
|
||||||
#define BLOCK_LENGTH 64
|
#define BLOCK_LENGTH 64
|
||||||
|
|
||||||
union _buffer {
|
|
||||||
uint8_t b[BLOCK_LENGTH];
|
|
||||||
uint32_t w[BLOCK_LENGTH/4];
|
|
||||||
} buffer;
|
|
||||||
union _state {
|
|
||||||
uint8_t b[HASH_LENGTH];
|
|
||||||
uint32_t w[HASH_LENGTH/4];
|
|
||||||
} state;
|
|
||||||
|
|
||||||
uint8_t bufferOffset;
|
|
||||||
uint32_t byteCount;
|
|
||||||
uint8_t keyBuffer[BLOCK_LENGTH];
|
|
||||||
uint8_t innerHash[HASH_LENGTH];
|
|
||||||
|
|
||||||
void init(void);
|
void init(void);
|
||||||
void initHmac(const uint8_t* secret, uint8_t secretLength);
|
void initHmac(const uint8_t* secret, uint8_t secretLength);
|
||||||
uint8_t* result(void);
|
uint8_t* result(void);
|
||||||
uint8_t* resultHmac(void);
|
uint8_t* resultHmac(void);
|
||||||
void write(uint8_t);
|
void write(uint8_t);
|
||||||
void writeArray(uint8_t *buffer, uint8_t size);
|
void writeArray(uint8_t *buffer, uint8_t size);
|
||||||
|
|
||||||
|
#endif // SHA1_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user