-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccrypt.h
80 lines (70 loc) · 1.76 KB
/
ccrypt.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef CRYPTO_H
#define CRYPTO_H
#include <stddef.h>
#include <stdint.h>
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define BLOCK_SIZE 32
#define BLOCK_BITS (BLOCK_SIZE * 8)
#define CIPHERTEXT_PTABLE_LENGTH (BLOCK_BITS + 8)
#define CIPHERTEXT_HEADER_LENGTH (CIPHERTEXT_PTABLE_LENGTH * 2)
#define CIPHERTEXT_BLOCK_SIZE (BLOCK_SIZE + 2)
#define CIPHERTEXT_PADDING_BYTES 2
typedef struct {
const uint8_t *key;
const size_t *text_ptable;
const size_t *key_ptable;
int wrote_header;
uint8_t *plaintext;
size_t ptsize;
} CCryptCipher;
typedef struct {
const uint8_t *key;
int section;
const size_t *text_rptable;
const size_t *key_ptable;
uint8_t *ciphertext;
size_t ctsize;
} CCryptDecipher;
typedef enum {
CCRYPT_DECIPHER_NO_ERROR,
CCRYPT_DECIPHER_INVALID_HEADER,
CCRYPT_DECIPHER_INVALID_LENGTH,
CCRYPT_DECIPHER_PADDING_ERROR
} CCryptDecipherResult;
CCryptCipher *CreateCCryptCipher(const uint8_t *key, size_t ksize);
void DestroyCCryptCipher(CCryptCipher *cipher);
uint8_t *UpdateCCryptCipher(
CCryptCipher *cipher,
const uint8_t *plaintext,
size_t ptsize,
size_t *szptr
);
uint8_t *EndCCryptCipher(
CCryptCipher *cipher,
const uint8_t *plaintext,
size_t ptsize,
size_t *szptr
);
CCryptDecipher *CreateCCryptDecipher(const uint8_t *key, size_t ksize);
void DestroyCCryptDecipher(CCryptDecipher *decipher);
CCryptDecipherResult UpdateCCryptDecipher(
CCryptDecipher *decipher,
const uint8_t *ciphertext,
size_t ctsize,
uint8_t **dest_ptr,
size_t *szptr
);
CCryptDecipherResult EndCCryptDecipher(
CCryptDecipher *decipher,
const uint8_t *ciphertext,
size_t ctsize,
uint8_t **dest_ptr,
size_t *szptr,
uint8_t *padding_ptr
);
#endif