forked from sunflyer/vlmcsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto.h
59 lines (45 loc) · 1.47 KB
/
crypto.h
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
#ifndef __crypto_h
#define __crypto_h
#ifndef CONFIG
#define CONFIG "config.h"
#endif // CONFIG
#include CONFIG
#include "types.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "endian.h"
#include <stdint.h>
//#define AES_ROUNDS (10)
#define AES_KEY_BYTES (16) // 128 Bits
#define AES_BLOCK_BYTES (16)
#define AES_BLOCK_WORDS (AES_BLOCK_BYTES / sizeof(DWORD))
#define AES_KEY_DWORDS (AES_KEY_BYTES / sizeof(DWORD))
//#define V4_ROUNDS (11)
#define V4_KEY_BYTES (20) // 160 Bits
#define ROR32(v, n) ( (v) << (32 - n) | (v) >> n )
void XorBlock(const BYTE *const in, const BYTE *out);
void AesCmacV4(BYTE *data, size_t len, BYTE *hash);
extern const BYTE AesKeyV5[];
extern const BYTE AesKeyV6[];
typedef struct {
DWORD Key[48]; // Supports a maximum of 160 key bits!
uint_fast8_t rounds;
} AesCtx;
void AesInitKey(AesCtx *Ctx, const BYTE *Key, int_fast8_t IsV6, int AesKeyBytes);
void AesEncryptBlock(const AesCtx *const Ctx, BYTE *block);
void AesDecryptBlock(const AesCtx *const Ctx, BYTE *block);
void AesEncryptCbc(const AesCtx *const Ctx, BYTE *iv, BYTE *data, size_t *len);
void AesDecryptCbc(const AesCtx *const Ctx, BYTE *iv, BYTE *data, size_t len);
void MixColumnsR(BYTE *restrict state);
#if defined(_CRYPTO_OPENSSL)
#include "crypto_openssl.h"
#elif defined(_CRYPTO_POLARSSL)
#include "crypto_polarssl.h"
#elif defined(_CRYPTO_WINDOWS)
#include "crypto_windows.h"
#else
#include "crypto_internal.h"
#endif
#endif // __crypto_h