px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_xtea.h
1#ifndef __PX_XTEA_H__
2#define __PX_XTEA_H__
3/* =============================================================================
4 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
5 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
6 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
7 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
8 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
9
10 Copyright (c) 2010 Pieter Conradie <https://piconomix.com>
11
12 License: MIT
13 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
14
15 Title: px_xtea.h : XTEA (eXtended Tiny Encryption Algorithm)
16 Author(s): Pieter Conradie
17 Creation Date: 2010-05-03
18
19============================================================================= */
20
21/**
22 * @ingroup UTILS
23 * @defgroup PX_XTEA px_xtea.h : XTEA (eXtended Tiny Encryption Algorithm)
24 *
25 * Block cipher encryption/decryption algorithm.
26 *
27 * File(s):
28 * - utils/inc/px_xtea.h
29 * - utils/src/px_xtea.c
30 *
31 * @see http://en.wikipedia.org/wiki/XTEA
32 *
33 * @{
34 */
35
36/* _____STANDARD INCLUDES____________________________________________________ */
37
38/* _____PROJECT INCLUDES_____________________________________________________ */
39#include "px_defs.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44/* _____DEFINITIONS__________________________________________________________ */
45/// Key size in bytes
46#define XTEA_KEY_SIZE_BYTES 16
47/// Data block size in bytes
48#define XTEA_BLOCK_SIZE_BYTES 8
49
50/* _____TYPE DEFINITIONS_____________________________________________________ */
51
52/* _____GLOBAL VARIABLES_____________________________________________________ */
53
54/* _____GLOBAL FUNCTION DECLARATIONS_________________________________________ */
55/**
56 * Initialise 128-bit key for encryption/decryption.
57 *
58 * @param key 4 x 32-bit values
59 */
60void px_xtea_init(const uint32_t key[4]);
61
62/**
63 * Encrypt 64-bit data with 128-bit key.
64 *
65 * @param data 2 x 32-bit values
66 */
67void px_xtea_encrypt(uint32_t data[2]);
68
69/**
70 * Encrypt a data buffer using Electronic Codebook (ECB) block cipher operation.
71 *
72 * If the data_in is not an exact multiple of the block size (8 bytes), zero
73 * padding is used for the last block. The data_out buffer MUST be a multiple
74 * of 8 bytes.
75 *
76 * The data can be encrypted in place by setting both the data_in and data_out
77 * pointer to the start of the buffer to be encrypted.
78 *
79 * @param data_in Pointer to data buffer to be encrypted
80 * @param data_out Pointer to data buffer to contain encrypted data
81 * @param nr_of_bytes Number of bytes to encrypt
82 *
83 * @returns size_t Number of bytes encrypted (multiple of block size)
84 */
85size_t px_xtea_encrypt_data_ecb(const uint8_t * data_in,
86 uint8_t * data_out,
87 size_t nr_of_bytes);
88
89/**
90 * Decrypt 64-bit data with 128-bit key.
91 *
92 * @param data 2 x 32-bit values
93 */
94void px_xtea_decrypt(uint32_t data[2]);
95
96/**
97 * Decrypt a data buffer using Electronic Codebook (ECB) block cipher operation.
98 *
99 * If the data_in is not an exact multiple of the block size (8 bytes), zero
100 * padding is used for the last block. The data_out buffer MUST be a multiple
101 * of 8 bytes.
102 *
103 * The data can be decrypted in place by setting both the data_in and data_out
104 * pointer to the start of the buffer to be decrypted.
105 *
106 * @param data_in Pointer to data buffer to be decrypted
107 * @param data_out Pointer to data buffer to contain decrypted data
108 * @param nr_of_bytes Number of bytes to decrypt
109 *
110 * @returns size_t Number of bytes decrypted (multiple of block size)
111 */
112size_t px_xtea_decrypt_data_ecb(const uint8_t * data_in,
113 uint8_t * data_out,
114 size_t nr_of_bytes);
115
116/* _____MACROS_______________________________________________________________ */
117
118#ifdef __cplusplus
119}
120#endif
121
122/// @}
123#endif
void px_xtea_decrypt(uint32_t data[2])
Decrypt 64-bit data with 128-bit key.
Definition: px_xtea.c:112
void px_xtea_encrypt(uint32_t data[2])
Encrypt 64-bit data with 128-bit key.
Definition: px_xtea.c:54
size_t px_xtea_decrypt_data_ecb(const uint8_t *data_in, uint8_t *data_out, size_t nr_of_bytes)
Decrypt a data buffer using Electronic Codebook (ECB) block cipher operation.
Definition: px_xtea.c:130
size_t px_xtea_encrypt_data_ecb(const uint8_t *data_in, uint8_t *data_out, size_t nr_of_bytes)
Encrypt a data buffer using Electronic Codebook (ECB) block cipher operation.
Definition: px_xtea.c:72
void px_xtea_init(const uint32_t key[4])
Initialise 128-bit key for encryption/decryption.
Definition: px_xtea.c:44