Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit 297706a

Browse files
author
Constanza Heath
committed
Adding ECC_DH, ECC_DSA, ECC_UTILS, and CMAC test cases. Adjusting namespacing to clarify when TC_ is for TinyCrypt vs Test Case.
Signed-off-by: Constanza Heath <[email protected]>
1 parent c450df3 commit 297706a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2575
-457
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
2.0.0

documentation/tinycrypt.rst

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.. _crypto:
21

32
TinyCrypt Cryptographic Library
43
###############################

lib/Makefile

+22-20
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,41 @@
99
include ../config.mk
1010

1111
# Edit the OBJS content to add/remove primitives needed from TinyCrypt library:
12-
OBJS = utils.o \
13-
aes_decrypt.o \
12+
OBJS = aes_decrypt.o \
1413
aes_encrypt.o \
1514
cbc_mode.o \
1615
ctr_mode.o \
1716
ctr_prng.o \
18-
ccm_mode.o \
19-
cmac_mode.o \
2017
hmac.o \
2118
hmac_prng.o \
2219
sha256.o \
2320
ecc.o \
2421
ecc_dh.o \
25-
ecc_dsa.o
22+
ecc_dsa.o \
23+
ccm_mode.o \
24+
cmac_mode.o \
25+
utils.o
2626

2727
all: $(OBJS)
2828

29+
.PHONY: clean
30+
2931
clean:
30-
$(RM) *.o *.gch core *dump *~
32+
-$(RM) *.exe *.o *~
3133

3234
# Dependencies
33-
aes_decrypt.o: aes_decrypt.c aes.h utils.o
34-
aes_encrypt.o: aes_encrypt.c aes.h utils.o
35-
cbc_mode.o: cbc_mode.c cbc_mode.h utils.o
36-
ctr_mode.o: ctr_mode.c ctr_mode.h utils.o
37-
ctr_prng.o: ctr_prng.c ctr_prng.h
38-
ccm_mode.o: ccm_mode.c ccm_mode.h utils.o
39-
cmac_mode.o: ccm_mode.c ccm_mode.h utils.o
40-
hmac.o: hmac.c hmac.h utils.o
41-
hmac_prng.o: hmac_prng.c hmac_prng.h utils.o
42-
sha256.o: sha256.c sha256.h utils.o
43-
ecc_dh.o: ecc_dh.c ecc_dh.h ecc.o
44-
ecc_dsa.o: ecc_dsa.c ecc_dsa.h ecc.o
45-
ecc.o: ecc.c ecc.h
46-
utils.o: utils.c utils.h
35+
aes_decrypt.o: aes.h constants.h utils.h
36+
aes_encrypt.o: aes.h constants.h utils.h
37+
cbc_mode.o: cbc_mode.h constants.h utils.h
38+
ctr_mode.o: ctr_mode.h constants.h utils.h
39+
ctr_prng.o: ctr_prng.h constants.h utils.h
40+
ccm_mode.o: ccm_mode.h constants.h utils.h
41+
cmac_mode.o: cmac_mode.h aes.h constants.h utils.h
42+
hmac.o: hmac.h constants.h utils.h
43+
hmac_prng.o: hmac_prng.h constants.h utils.h
44+
sha256.o: sha256.h constants.h utils.h
45+
ecc.o: ecc.h
46+
ecc_dh.o: ecc_dh.h
47+
ecc_dsa.o: ecc_dsa.h
48+
utils.o: utils.h
4749

lib/include/tinycrypt/aes.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ typedef struct tc_aes_key_sched_struct *TCAesKeySched_t;
6969
/**
7070
* @brief Set AES-128 encryption key
7171
* Uses key k to initialize s
72-
* @return returns TC_SUCCESS (1)
73-
* returns TC_FAIL (0) if: s == NULL or k == NULL
72+
* @return returns TC_CRYPTO_SUCCESS (1)
73+
* returns TC_CRYPTO_FAIL (0) if: s == NULL or k == NULL
7474
* @note This implementation skips the additional steps required for keys
7575
* larger than 128 bits, and must not be used for AES-192 or
7676
* AES-256 key schedule -- see FIPS 197 for details
@@ -85,8 +85,8 @@ int32_t tc_aes128_set_encrypt_key(TCAesKeySched_t s, const uint8_t *k);
8585
* schedule s
8686
* @note Assumes s was initialized by aes_set_encrypt_key;
8787
* out and in point to 16 byte buffers
88-
* @return returns TC_SUCCESS (1)
89-
* returns TC_FAIL (0) if: out == NULL or in == NULL or s == NULL
88+
* @return returns TC_CRYPTO_SUCCESS (1)
89+
* returns TC_CRYPTO_FAIL (0) if: out == NULL or in == NULL or s == NULL
9090
* @param out IN/OUT -- buffer to receive ciphertext block
9191
* @param in IN -- a plaintext block to encrypt
9292
* @param s IN -- initialized AES key schedule
@@ -98,8 +98,8 @@ int32_t tc_aes_encrypt(uint8_t *out,
9898
/**
9999
* @brief Set the AES-128 decryption key
100100
* Uses key k to initialize s
101-
* @return returns TC_SUCCESS (1)
102-
* returns TC_FAIL (0) if: s == NULL or k == NULL
101+
* @return returns TC_CRYPTO_SUCCESS (1)
102+
* returns TC_CRYPTO_FAIL (0) if: s == NULL or k == NULL
103103
* @note This is the implementation of the straightforward inverse cipher
104104
* using the cipher documented in FIPS-197 figure 12, not the
105105
* equivalent inverse cipher presented in Figure 15
@@ -114,8 +114,8 @@ int32_t tc_aes128_set_decrypt_key(TCAesKeySched_t s, const uint8_t *k);
114114
/**
115115
* @brief AES-128 Encryption procedure
116116
* Decrypts in buffer into out buffer under key schedule s
117-
* @return returns TC_SUCCESS (1)
118-
* returns TC_FAIL (0) if: out is NULL or in is NULL or s is NULL
117+
* @return returns TC_CRYPTO_SUCCESS (1)
118+
* returns TC_CRYPTO_FAIL (0) if: out is NULL or in is NULL or s is NULL
119119
* @note Assumes s was initialized by aes_set_encrypt_key
120120
* out and in point to 16 byte buffers
121121
* @param out IN/OUT -- buffer to receive ciphertext block

lib/include/tinycrypt/cbc_mode.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ extern "C" {
8484
* @brief CBC encryption procedure
8585
* CBC encrypts inlen bytes of the in buffer into the out buffer
8686
* using the encryption key schedule provided, prepends iv to out
87-
* @return returns TC_SUCCESS (1)
88-
* returns TC_FAIL (0) if:
87+
* @return returns TC_CRYPTO_SUCCESS (1)
88+
* returns TC_CRYPTO_FAIL (0) if:
8989
* out == NULL or
9090
* in == NULL or
9191
* ctr == NULL or
@@ -115,8 +115,8 @@ int32_t tc_cbc_mode_encrypt(uint8_t *out, uint32_t outlen, const uint8_t *in,
115115
* @brief CBC decryption procedure
116116
* CBC decrypts inlen bytes of the in buffer into the out buffer
117117
* using the provided encryption key schedule
118-
* @return returns TC_SUCCESS (1)
119-
* returns TC_FAIL (0) if:
118+
* @return returns TC_CRYPTO_SUCCESS (1)
119+
* returns TC_CRYPTO_FAIL (0) if:
120120
* out == NULL or
121121
* in == NULL or
122122
* sched == NULL or

lib/include/tinycrypt/ccm_mode.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ typedef struct tc_ccm_mode_struct {
9696

9797
/**
9898
* @brief CCM configuration procedure
99-
* @return returns TC_SUCCESS (1)
100-
* returns TC_FAIL (0) if:
99+
* @return returns TC_CRYPTO_SUCCESS (1)
100+
* returns TC_CRYPTO_FAIL (0) if:
101101
* c == NULL or
102102
* sched == NULL or
103103
* nonce == NULL or
@@ -113,8 +113,8 @@ int32_t tc_ccm_config(TCCcmMode_t c, TCAesKeySched_t sched, uint8_t *nonce,
113113

114114
/**
115115
* @brief CCM tag generation and encryption procedure
116-
* @return returns TC_SUCCESS (1)
117-
* returns TC_FAIL (0) if:
116+
* @return returns TC_CRYPTO_SUCCESS (1)
117+
* returns TC_CRYPTO_FAIL (0) if:
118118
* out == NULL or
119119
* c == NULL or
120120
* ((plen > 0) and (payload == NULL)) or
@@ -155,8 +155,8 @@ int32_t tc_ccm_generation_encryption(uint8_t *out, const uint8_t *associated_dat
155155

156156
/**
157157
* @brief CCM decryption and tag verification procedure
158-
* @return returns TC_SUCCESS (1)
159-
* returns TC_FAIL (0) if:
158+
* @return returns TC_CRYPTO_SUCCESS (1)
159+
* returns TC_CRYPTO_FAIL (0) if:
160160
* out == NULL or
161161
* c == NULL or
162162
* ((plen > 0) and (payload == NULL)) or

lib/include/tinycrypt/cmac_mode.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ typedef struct tc_cmac_struct {
130130

131131
/**
132132
* @brief Configures the CMAC state to use the given AES key
133-
* @return returns TC_SUCCESS (1) after having configured the CMAC state
134-
* returns TC_FAIL (0) if:
133+
* @return returns TC_CRYPTO_SUCCESS (1) after having configured the CMAC state
134+
* returns TC_CRYPTO_FAIL (0) if:
135135
* s == NULL or
136136
* key == NULL
137137
*
@@ -144,8 +144,8 @@ int32_t tc_cmac_setup(TCCmacState_t s, const uint8_t *key,
144144

145145
/**
146146
* @brief Erases the CMAC state
147-
* @return returns TC_SUCCESS (1) after having configured the CMAC state
148-
* returns TC_FAIL (0) if:
147+
* @return returns TC_CRYPTO_SUCCESS (1) after having configured the CMAC state
148+
* returns TC_CRYPTO_FAIL (0) if:
149149
* s == NULL
150150
*
151151
* @param s IN/OUT -- the state to erase
@@ -154,8 +154,8 @@ int32_t tc_cmac_erase(TCCmacState_t s);
154154

155155
/**
156156
* @brief Initializes a new CMAC computation
157-
* @return returns TC_SUCCESS (1) after having initialized the CMAC state
158-
* returns TC_FAIL (0) if:
157+
* @return returns TC_CRYPTO_SUCCESS (1) after having initialized the CMAC state
158+
* returns TC_CRYPTO_FAIL (0) if:
159159
* s == NULL
160160
*
161161
* @param s IN/OUT -- the state to initialize
@@ -164,8 +164,8 @@ int32_t tc_cmac_init(TCCmacState_t s);
164164

165165
/**
166166
* @brief Incrementally computes CMAC over the next data segment
167-
* @return returns TC_SUCCESS (1) after successfully updating the CMAC state
168-
* returns TC_FAIL (0) if:
167+
* @return returns TC_CRYPTO_SUCCESS (1) after successfully updating the CMAC state
168+
* returns TC_CRYPTO_FAIL (0) if:
169169
* s == NULL or
170170
* if data == NULL when dlen > 0
171171
*
@@ -177,8 +177,8 @@ int32_t tc_cmac_update(TCCmacState_t s, const uint8_t *data, size_t dlen);
177177

178178
/**
179179
* @brief Generates the tag from the CMAC state
180-
* @return returns TC_SUCCESS (1) after successfully generating the tag
181-
* returns TC_FAIL (0) if:
180+
* @return returns TC_CRYPTO_SUCCESS (1) after successfully generating the tag
181+
* returns TC_CRYPTO_FAIL (0) if:
182182
* tag == NULL or
183183
* s == NULL
184184
*

lib/include/tinycrypt/ctr_mode.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ extern "C" {
7777
/**
7878
* @brief CTR mode encryption/decryption procedure.
7979
* CTR mode encrypts (or decrypts) inlen bytes from in buffer into out buffer
80-
* @return returns TC_SUCCESS (1)
81-
* returns TC_FAIL (0) if:
80+
* @return returns TC_CRYPTO_SUCCESS (1)
81+
* returns TC_CRYPTO_FAIL (0) if:
8282
* out == NULL or
8383
* in == NULL or
8484
* ctr == NULL or

lib/include/tinycrypt/ctr_prng.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
#include <tinycrypt/aes.h>
6363

64+
#define TC_CTR_PRNG_RESEED_REQ -1
65+
6466
#ifdef __cplusplus
6567
extern "C" {
6668
#endif
@@ -81,8 +83,8 @@ typedef struct
8183
/**
8284
* @brief CTR-PRNG initialization procedure
8385
* Initializes prng context with entropy and personalization string (if any)
84-
* @return returns TC_SUCCESS (1)
85-
* returns TC_FAIL (0) if:
86+
* @return returns TC_CRYPTO_SUCCESS (1)
87+
* returns TC_CRYPTO_FAIL (0) if:
8688
* ctx == NULL,
8789
* entropy == NULL,
8890
* entropyLen < (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE)
@@ -106,8 +108,8 @@ int32_t tc_ctr_prng_init(TCCtrPrng_t * const ctx,
106108
/**
107109
* @brief CTR-PRNG reseed procedure
108110
* Mixes entropy and additional_input into the prng context
109-
* @return returns TC_SUCCESS (1)
110-
* returns TC_FAIL (0) if:
111+
* @return returns TC_CRYPTO_SUCCESS (1)
112+
* returns TC_CRYPTO_FAIL (0) if:
111113
* ctx == NULL,
112114
* entropy == NULL,
113115
* entropylen < (TC_AES_KEY_SIZE + TC_AES_BLOCK_SIZE)
@@ -131,9 +133,9 @@ int32_t tc_ctr_prng_reseed(TCCtrPrng_t * const ctx,
131133
/**
132134
* @brief CTR-PRNG generate procedure
133135
* Generates outlen pseudo-random bytes into out buffer, updates prng
134-
* @return returns TC_SUCCESS (1)
135-
* returns TC_RESEED_REQ (-1) if a reseed is needed
136-
* returns TC_FAIL (0) if:
136+
* @return returns TC_CRYPTO_SUCCESS (1)
137+
* returns TC_CTR_PRNG_RESEED_REQ (-1) if a reseed is needed
138+
* returns TC_CRYPTO_FAIL (0) if:
137139
* ctx == NULL,
138140
* out == NULL,
139141
* outlen >= 2^16

lib/include/tinycrypt/ecc.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ void EccPoint_mult(EccPointJacobi *p_result, EccPoint *p_point,
277277

278278
/*
279279
* @brief Convert an integer in standard octet representation to native format.
280-
* @return returns TC_SUCCESS (1)
281-
* returns TC_FAIL (0) if:
280+
* @return returns TC_CRYPTO_SUCCESS (1)
281+
* returns TC_CRYPTO_FAIL (0) if:
282282
* out == NULL or
283283
* c == NULL or
284284
* ((plen > 0) and (payload == NULL)) or
@@ -296,8 +296,8 @@ void ecc_bytes2native(uint32_t p_native[NUM_ECC_DIGITS],
296296

297297
/*
298298
* @brief Convert an integer in native format to standard octet representation.
299-
* @return returns TC_SUCCESS (1)
300-
* returns TC_FAIL (0) if:
299+
* @return returns TC_CRYPTO_SUCCESS (1)
300+
* returns TC_CRYPTO_FAIL (0) if:
301301
* out == NULL or
302302
* c == NULL or
303303
* ((plen > 0) and (payload == NULL)) or

lib/include/tinycrypt/ecc_dh.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ extern "C" {
8080

8181
/**
8282
* @brief Create a public/private key pair.
83-
* @return returns TC_SUCCESS (1) if the key pair was generated successfully
84-
* returns TC_FAIL (0) if:
83+
* @return returns TC_CRYPTO_SUCCESS (1) if the key pair was generated successfully
84+
* returns TC_CRYPTO_FAIL (0) if:
8585
* the private key is 0
8686
8787
* @param p_publicKey OUT -- the point representing the public key.
@@ -116,8 +116,8 @@ int32_t ecc_valid_public_key(EccPoint *p_publicKey);
116116
/**
117117
* @brief Compute a shared secret given your secret key and someone else's
118118
* public key.
119-
* @return returns TC_SUCCESS (1) if the shared secret was computed successfully
120-
* returns TC_FAIL (0) otherwise
119+
* @return returns TC_CRYPTO_SUCCESS (1) if the shared secret was computed successfully
120+
* returns TC_CRYPTO_FAIL (0) otherwise
121121
*
122122
* @param p_secret OUT -- The shared secret value.
123123
* @param p_publicKey IN -- The public key of the remote party.

lib/include/tinycrypt/ecc_dsa.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ extern "C" {
8787

8888
/**
8989
* @brief Generate an ECDSA signature for a given hash value.
90-
* @return returns TC_SUCCESS (1) if the the signature generated successfully
91-
* returns TC_FAIL (0) if:
90+
* @return returns TC_CRYPTO_SUCCESS (1) if the the signature generated successfully
91+
* returns TC_CRYPTO_FAIL (0) if:
9292
* r == 0 or
9393
* p_random == 0
9494
*
@@ -112,8 +112,8 @@ int32_t ecdsa_sign(uint32_t r[NUM_ECC_DIGITS], uint32_t s[NUM_ECC_DIGITS],
112112

113113
/**
114114
* @brief Verify an ECDSA signature.
115-
* @return returns TC_SUCCESS (1) if the the signature generated successfully
116-
* returns TC_FAIL (0) if:
115+
* @return returns TC_CRYPTO_SUCCESS (1) if the the signature generated successfully
116+
* returns TC_CRYPTO_FAIL (0) if:
117117
* r == 0 or
118118
* p_random == 0
119119
*

lib/include/tinycrypt/hmac.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ typedef struct tc_hmac_state_struct *TCHmacState_t;
8080
/**
8181
* @brief HMAC set key procedure
8282
* Configures ctx to use key
83-
* @return returns TC_SUCCESS (1)
84-
* returns TC_FAIL (0) if
83+
* @return returns TC_CRYPTO_SUCCESS (1)
84+
* returns TC_CRYPTO_FAIL (0) if
8585
* ctx == NULL or
8686
* key == NULL or
8787
* key_size == 0
@@ -96,17 +96,17 @@ int32_t tc_hmac_set_key(TCHmacState_t ctx,
9696
/**
9797
* @brief HMAC init procedure
9898
* Initializes ctx to begin the next HMAC operation
99-
* @return returns TC_SUCCESS (1)
100-
* returns TC_FAIL (0) if: ctx == NULL or key == NULL
99+
* @return returns TC_CRYPTO_SUCCESS (1)
100+
* returns TC_CRYPTO_FAIL (0) if: ctx == NULL or key == NULL
101101
* @param ctx IN/OUT -- struct tc_hmac_state_struct buffer to init
102102
*/
103103
int32_t tc_hmac_init(TCHmacState_t ctx);
104104

105105
/**
106106
* @brief HMAC update procedure
107107
* Mixes data_length bytes addressed by data into state
108-
* @return returns TC_SUCCCESS (1)
109-
* returns TC_FAIL (0) if: ctx == NULL or key == NULL
108+
* @return returns TC_CRYPTO_SUCCCESS (1)
109+
* returns TC_CRYPTO_FAIL (0) if: ctx == NULL or key == NULL
110110
* @note Assumes state has been initialized by tc_hmac_init
111111
* @param ctx IN/OUT -- state of HMAC computation so far
112112
* @param data IN -- data to incorporate into state
@@ -119,8 +119,8 @@ int32_t tc_hmac_update(TCHmacState_t ctx,
119119
/**
120120
* @brief HMAC final procedure
121121
* Writes the HMAC tag into the tag buffer
122-
* @return returns TC_SUCCESS (1)
123-
* returns TC_FAIL (0) if:
122+
* @return returns TC_CRYPTO_SUCCESS (1)
123+
* returns TC_CRYPTO_FAIL (0) if:
124124
* tag == NULL or
125125
* ctx == NULL or
126126
* key == NULL or

0 commit comments

Comments
 (0)