@@ -80,6 +80,9 @@ static const uint8_t test_c[147] = {
8080
8181static void test_known (void )
8282{
83+ const Memory * mem = os_memory ();
84+ ck_assert (mem != nullptr );
85+
8386 uint8_t c [147 ];
8487 uint8_t m [131 ];
8588
@@ -88,19 +91,22 @@ static void test_known(void)
8891 ck_assert_msg (sizeof (test_c ) == sizeof (c ), "sanity check failed" );
8992 ck_assert_msg (sizeof (test_m ) == sizeof (m ), "sanity check failed" );
9093
91- const uint16_t clen = encrypt_data (bobpk , alicesk , test_nonce , test_m , sizeof (test_m ) / sizeof (uint8_t ), c );
94+ const uint16_t clen = encrypt_data (mem , bobpk , alicesk , test_nonce , test_m , sizeof (test_m ) / sizeof (uint8_t ), c );
9295
9396 ck_assert_msg (memcmp (test_c , c , sizeof (c )) == 0 , "cyphertext doesn't match test vector" );
9497 ck_assert_msg (clen == sizeof (c ) / sizeof (uint8_t ), "wrong ciphertext length" );
9598
96- const uint16_t mlen = decrypt_data (bobpk , alicesk , test_nonce , test_c , sizeof (test_c ) / sizeof (uint8_t ), m );
99+ const uint16_t mlen = decrypt_data (mem , bobpk , alicesk , test_nonce , test_c , sizeof (test_c ) / sizeof (uint8_t ), m );
97100
98101 ck_assert_msg (memcmp (test_m , m , sizeof (m )) == 0 , "decrypted text doesn't match test vector" );
99102 ck_assert_msg (mlen == sizeof (m ) / sizeof (uint8_t ), "wrong plaintext length" );
100103}
101104
102105static void test_fast_known (void )
103106{
107+ const Memory * mem = os_memory ();
108+ ck_assert (mem != nullptr );
109+
104110 uint8_t k [CRYPTO_SHARED_KEY_SIZE ];
105111 uint8_t c [147 ];
106112 uint8_t m [131 ];
@@ -112,19 +118,21 @@ static void test_fast_known(void)
112118 ck_assert_msg (sizeof (test_c ) == sizeof (c ), "sanity check failed" );
113119 ck_assert_msg (sizeof (test_m ) == sizeof (m ), "sanity check failed" );
114120
115- const uint16_t clen = encrypt_data_symmetric (k , test_nonce , test_m , sizeof (test_m ) / sizeof (uint8_t ), c );
121+ const uint16_t clen = encrypt_data_symmetric (mem , k , test_nonce , test_m , sizeof (test_m ) / sizeof (uint8_t ), c );
116122
117123 ck_assert_msg (memcmp (test_c , c , sizeof (c )) == 0 , "cyphertext doesn't match test vector" );
118124 ck_assert_msg (clen == sizeof (c ) / sizeof (uint8_t ), "wrong ciphertext length" );
119125
120- const uint16_t mlen = decrypt_data_symmetric (k , test_nonce , test_c , sizeof (test_c ) / sizeof (uint8_t ), m );
126+ const uint16_t mlen = decrypt_data_symmetric (mem , k , test_nonce , test_c , sizeof (test_c ) / sizeof (uint8_t ), m );
121127
122128 ck_assert_msg (memcmp (test_m , m , sizeof (m )) == 0 , "decrypted text doesn't match test vector" );
123129 ck_assert_msg (mlen == sizeof (m ) / sizeof (uint8_t ), "wrong plaintext length" );
124130}
125131
126132static void test_endtoend (void )
127133{
134+ const Memory * mem = os_memory ();
135+ ck_assert (mem != nullptr );
128136 const Random * rng = os_random ();
129137 ck_assert (rng != nullptr );
130138
@@ -166,21 +174,21 @@ static void test_endtoend(void)
166174 ck_assert_msg (memcmp (k1 , k2 , CRYPTO_SHARED_KEY_SIZE ) == 0 , "encrypt_precompute: bad" );
167175
168176 //Encrypt all four ways
169- const uint16_t c1len = encrypt_data (pk2 , sk1 , n , m , mlen , c1 );
170- const uint16_t c2len = encrypt_data (pk1 , sk2 , n , m , mlen , c2 );
171- const uint16_t c3len = encrypt_data_symmetric (k1 , n , m , mlen , c3 );
172- const uint16_t c4len = encrypt_data_symmetric (k2 , n , m , mlen , c4 );
177+ const uint16_t c1len = encrypt_data (mem , pk2 , sk1 , n , m , mlen , c1 );
178+ const uint16_t c2len = encrypt_data (mem , pk1 , sk2 , n , m , mlen , c2 );
179+ const uint16_t c3len = encrypt_data_symmetric (mem , k1 , n , m , mlen , c3 );
180+ const uint16_t c4len = encrypt_data_symmetric (mem , k2 , n , m , mlen , c4 );
173181
174182 ck_assert_msg (c1len == c2len && c1len == c3len && c1len == c4len , "cyphertext lengths differ" );
175183 ck_assert_msg (c1len == mlen + (uint16_t )CRYPTO_MAC_SIZE , "wrong cyphertext length" );
176184 ck_assert_msg (memcmp (c1 , c2 , c1len ) == 0 && memcmp (c1 , c3 , c1len ) == 0
177185 && memcmp (c1 , c4 , c1len ) == 0 , "crypertexts differ" );
178186
179187 //Decrypt all four ways
180- const uint16_t m1len = decrypt_data (pk2 , sk1 , n , c1 , c1len , m1 );
181- const uint16_t m2len = decrypt_data (pk1 , sk2 , n , c1 , c1len , m2 );
182- const uint16_t m3len = decrypt_data_symmetric (k1 , n , c1 , c1len , m3 );
183- const uint16_t m4len = decrypt_data_symmetric (k2 , n , c1 , c1len , m4 );
188+ const uint16_t m1len = decrypt_data (mem , pk2 , sk1 , n , c1 , c1len , m1 );
189+ const uint16_t m2len = decrypt_data (mem , pk1 , sk2 , n , c1 , c1len , m2 );
190+ const uint16_t m3len = decrypt_data_symmetric (mem , k1 , n , c1 , c1len , m3 );
191+ const uint16_t m4len = decrypt_data_symmetric (mem , k2 , n , c1 , c1len , m4 );
184192
185193 ck_assert_msg (m1len == m2len && m1len == m3len && m1len == m4len , "decrypted text lengths differ" );
186194 ck_assert_msg (m1len == mlen , "wrong decrypted text length" );
@@ -192,6 +200,8 @@ static void test_endtoend(void)
192200
193201static void test_large_data (void )
194202{
203+ const Memory * mem = os_memory ();
204+ ck_assert (mem != nullptr );
195205 const Random * rng = os_random ();
196206 ck_assert (rng != nullptr );
197207 uint8_t k [CRYPTO_SHARED_KEY_SIZE ];
@@ -216,13 +226,13 @@ static void test_large_data(void)
216226 //Generate key
217227 rand_bytes (rng , k , CRYPTO_SHARED_KEY_SIZE );
218228
219- const uint16_t c1len = encrypt_data_symmetric (k , n , m1 , m1_size , c1 );
220- const uint16_t c2len = encrypt_data_symmetric (k , n , m2 , m2_size , c2 );
229+ const uint16_t c1len = encrypt_data_symmetric (mem , k , n , m1 , m1_size , c1 );
230+ const uint16_t c2len = encrypt_data_symmetric (mem , k , n , m2 , m2_size , c2 );
221231
222232 ck_assert_msg (c1len == m1_size + CRYPTO_MAC_SIZE , "could not encrypt" );
223233 ck_assert_msg (c2len == m2_size + CRYPTO_MAC_SIZE , "could not encrypt" );
224234
225- const uint16_t m1plen = decrypt_data_symmetric (k , n , c1 , c1len , m1prime );
235+ const uint16_t m1plen = decrypt_data_symmetric (mem , k , n , c1 , c1len , m1prime );
226236
227237 ck_assert_msg (m1plen == m1_size , "decrypted text lengths differ" );
228238 ck_assert_msg (memcmp (m1prime , m1 , m1_size ) == 0 , "decrypted texts differ" );
@@ -236,6 +246,8 @@ static void test_large_data(void)
236246
237247static void test_large_data_symmetric (void )
238248{
249+ const Memory * mem = os_memory ();
250+ ck_assert (mem != nullptr );
239251 const Random * rng = os_random ();
240252 ck_assert (rng != nullptr );
241253 uint8_t k [CRYPTO_SYMMETRIC_KEY_SIZE ];
@@ -256,10 +268,10 @@ static void test_large_data_symmetric(void)
256268 //Generate key
257269 new_symmetric_key (rng , k );
258270
259- const uint16_t c1len = encrypt_data_symmetric (k , n , m1 , m1_size , c1 );
271+ const uint16_t c1len = encrypt_data_symmetric (mem , k , n , m1 , m1_size , c1 );
260272 ck_assert_msg (c1len == m1_size + CRYPTO_MAC_SIZE , "could not encrypt data" );
261273
262- const uint16_t m1plen = decrypt_data_symmetric (k , n , c1 , c1len , m1prime );
274+ const uint16_t m1plen = decrypt_data_symmetric (mem , k , n , c1 , c1len , m1prime );
263275
264276 ck_assert_msg (m1plen == m1_size , "decrypted text lengths differ" );
265277 ck_assert_msg (memcmp (m1prime , m1 , m1_size ) == 0 , "decrypted texts differ" );
@@ -271,6 +283,8 @@ static void test_large_data_symmetric(void)
271283
272284static void test_very_large_data (void )
273285{
286+ const Memory * mem = os_memory ();
287+ ck_assert (mem != nullptr );
274288 const Random * rng = os_random ();
275289 ck_assert (rng != nullptr );
276290
@@ -287,7 +301,7 @@ static void test_very_large_data(void)
287301 ck_assert (plain != nullptr );
288302 ck_assert (encrypted != nullptr );
289303
290- encrypt_data (pk , sk , nonce , plain , plain_size , encrypted );
304+ encrypt_data (mem , pk , sk , nonce , plain , plain_size , encrypted );
291305
292306 free (encrypted );
293307 free (plain );
0 commit comments