-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto.h
More file actions
102 lines (85 loc) · 2.61 KB
/
crypto.h
File metadata and controls
102 lines (85 loc) · 2.61 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
Copyright (C) 2021 Embed Creativity LLC
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef CRYPTO_H
#define CRYPTO_H
#include <stdint.h> /* for unsigned values*/
#include <stdio.h> /* Standard input/output definitions */
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <winsock.h> // for ntohl
#define PACKED
#pragma pack(push,1)
#else
#include <netinet/in.h> // for htonl, ntohl
#define PACKED __attribute__ ((__packed__))
#endif
#define IV_LEN 16
#define KEY_LEN 16
typedef void* CryptoHandle_T;
/* CreateCryptoHandle()
* input params:
* uint8_t* pIV
* uint8_t* pKey
*
* return CryptoHandle_T*
* NULL if allocation failed
*/
typedef CryptoHandle_T* (*CreateCryptoHandle_T) (
const uint8_t* pIV,
const uint8_t* pKey );
/* FreeCryptoHandle()
* input params:
* CryptoHandle_T* pHandle;
*
*/
typedef void (*FreeCryptoHandle_T) (
CryptoHandle_T* pHandle);
/* Encrypt()
* input params:
* CryptoHandle_T* pHandle
* uint8_t* pPlainText - input plain text buffer
* uint8_t* pCipherText - pre-allocated output buffer
* uint32_t count - number of bytes to be encrypted
*/
typedef void (*Encrypt_T) (
CryptoHandle_T* pHandle,
uint8_t* pPlainText,
uint8_t* pCipherText,
uint32_t count );
/* Decrypt()
* input params:
* CryptoHandle_T* pHandle
* uint8_t* pCipherText - input ciphertext buffer
* uint8_t* pPlainText - pre-allocated output buffer
* uint32_t count - number of bytes to be decrypted
*/
typedef void (*Decrypt_T) (
CryptoHandle_T* pHandle,
uint8_t* pCipherText,
uint8_t* pPlainText,
uint32_t count );
// This is the Crypto interface
typedef struct _CryptoInterface_T {
CreateCryptoHandle_T CreateCryptoHandle;
FreeCryptoHandle_T FreeCryptoHandle;
Encrypt_T Encrypt;
Decrypt_T Decrypt;
} PACKED CryptoInterface_T;
#ifdef WIN32
#pragma pack(pop)
#undef PACKED
#endif
#endif // CRYPTO_H