Skip to content

Conversation

@fjmolinas
Copy link
Collaborator

This PR is re-working the work done in #94 and adding Tinycrypt support for hkdf, if intel/tinycrypt#43 is included.

Regarding the todo list on #94:

  • Implementation completeness is checked, but allowing it to error out on the invalid salt size
  • Checked code style by uncrustifying

What is not addressed is the potential requirement for a streaming API.

@chrysn

@fjmolinas fjmolinas requested a review from bergzand February 23, 2022 14:55
@chrysn
Copy link
Contributor

chrysn commented Feb 24, 2022

Looks good to me; didn't test it, but then that's what the tests are for (and they are run for sodium; tinycrypt probably doesn't have the patch applied yet, but I trust you've run these locally, and whenever it gets updated the tests will spot anything that's wrong again).

fjmolinas and others added 3 commits February 24, 2022 14:35
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: Marco vR <marcovr@live.de>
Co-authored-by: chrysn <chrysn@fsfe.org>
Co-authored-by: Marco vR <marcovr@live.de>
HKDF support in tinycrypt is not integrated into the master branch
so intel/tinycrypt#43 must be included.
@fjmolinas
Copy link
Collaborator Author

Testing:

CRYPTO=tinycrypt make clean test
rm -rf bin
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_common.o src/cose_common.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_crypto.o src/cose_crypto.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_encrypt.o src/cose_encrypt.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_hdr.o src/cose_hdr.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_hkdf.o src/cose_hkdf.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_key.o src/cose_key.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_recipient.o src/cose_recipient.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_signature.o src/cose_signature.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/cose_sign.o src/cose_sign.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/crypt/keygen_symm.o src/crypt/keygen_symm.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/crypt/tinycrypt.o src/crypt/tinycrypt.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/tests/crypto.o tests/crypto.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/tests/encrypt.o tests/encrypt.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/tests/hdr.o tests/hdr.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/tests/hkdf.o tests/hkdf.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/tests/sign.o tests/sign.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/tests/suit.o tests/suit.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage -c -o bin/objs/tests/test.o tests/test.c
cc -fPIC -Wall -Wextra -pedantic -Werror -Wshadow -Iinclude -I/usr/include -I/home/francisco/workspace/libcose/../nanocbor//include -Os -g3 -DCRYPTO_TINYCRYPT -I/home/francisco/workspace/libcose/../tinycrypt/lib/include  -coverage bin/objs/cose_common.o bin/objs/cose_crypto.o bin/objs/cose_encrypt.o bin/objs/cose_hdr.o bin/objs/cose_hkdf.o bin/objs/cose_key.o bin/objs/cose_recipient.o bin/objs/cose_signature.o bin/objs/cose_sign.o bin/objs/crypt/keygen_symm.o bin/objs/crypt/tinycrypt.o  bin/objs/tests/crypto.o bin/objs/tests/encrypt.o bin/objs/tests/hdr.o bin/objs/tests/hkdf.o bin/objs/tests/sign.o bin/objs/tests/suit.o bin/objs/tests/test.o -o bin/test  -Wl,/home/francisco/workspace/libcose/../nanocbor//bin/libnanocbor.so /home/francisco/workspace/libcose/../tinycrypt/lib/libtinycrypt.a -Wl,-lcunit
LD_LIBRARY_PATH="/home/francisco/workspace/libcose/../nanocbor//bin" bin/test


     CUnit - A unit testing framework for C - Version 2.1-3
     http://cunit.sourceforge.net/


Suite: Suite_hdr
  Test: Simple cbor to hdr conversion ...passed
  Test: Text cbor to hdr conversion ...passed
  Test: Bytes cbor to hdr conversion ...passed
  Test: header to CBOR conversion ...passed
  Test: header with string to CBOR conversion ...passed
  Test: header with bytes to CBOR conversion ...passed
Suite: Suite_signatures
  Test: Sign with 1 sig ...Encode size: 104
D28443A10126A104506B6F656E406578616D706C652E6F72674C496E70757420737472696E675840FBA65330FB66CF7E415B10629A2AB986CDE2648479A3F0DD0A01597B0E7B209E3112BBCB43CB5EC0D66A561A4F03682FC0B151A38B394700292D7D7AF8268AFBpassed
  Test: Sign with 1 sig untagged ...passed
  Test: Sign with two sigs ...D8628441A0A04C496E70757420737472696E67828343A10126A104506B6F656E406578616D706C652E6E657458403A84515092A418A72061E559792DE52A9AA8D3DD14BCCCDC54C15836772820477B107DF0A4976F59F1DF922B7CBD9CD711D1CD7E7161D4B3332FACD74A0E2CB88343A10126A104506B6F656E406578616D706C652E6F7267584008C978FF393EB479E60BA59766B04EE1D4D69A9162316A25D9CDE00DE1062A1CA2CA819D1171781D8AD5C94235DA52DA39C58140DAE31A8261D330B889A0E150
passed
  Test: Content type header test ...passed
  Test: External payload header test ...passed
  Test: Sign1 Sig headers test ...passed
  Test: Sign Sig headers test ...
D8628441A0A04C496E70757420737472696E67828346A20126182D21A204506B6F656E406578616D706C652E6E6574182F225840E7854E038503E3327CAD8590CF625D192EFA5C7ED29D72788A376F378B69F7EFACB8FD42C5CC1E5E70CBE7D1768733BD54ED3370D9DA29B6634E2DC829FC9DCB8346A20126182A03A204506B6F656E406578616D706C652E6F7267182907584050F880412736FB47E31884882D93072D5C54ED60C13F19817775430C6AE04F1405E45093061928984BAADB04E228CDC18815E13D02B778162AB69ACBD00A2DD7
passed
  Test: Sign with aad test ...passed
Suite: Suite_encrypt
  Test: Encryption with encrypt0 over algos ...Testing AAD with 3 algos
Testing encryption with algo 10
D08343A1010AA1054D00000000000000000000000000581C3FD8F4AE3BD080C1E7E943003CADDA4FC9D18D42CFD70E94CEFB29B8
Testing encryption with algo 30
D08344A101181EA1054D0000000000000000000000000058243FD8F4AE3BD080C1E7E943003CADDA4FC9D18D429EACEE6EAABB17D18D0F5A42866DDCC9
passed
Suite: Suite_hkdf
  Test: RFC5869 HKDF-SHA256 test vector 1 ...passed
  Test: RFC5869 HKDF-SHA256 test vector 2 ...passed
  Test: RFC5869 HKDF-SHA256 test vector 3 ...passed
  Test: RFC8613 Key Derivation with ID Contex test vector 3 ...passed
  Test: cose_crypto_is_hkdf ...passed

Run Summary:    Type  Total    Ran Passed Failed Inactive
              suites      6      6    n/a      0        0
               tests     20     20     20      0        0
             asserts    111    111    111      0      n/a

Elapsed time =    0.082 seconds

@bergzand bergzand merged commit 195259f into bergzand:master Feb 24, 2022
@fjmolinas fjmolinas deleted the pr_hkdf branch February 24, 2022 13:40
@bergzand
Copy link
Owner

Thanks!

@fjmolinas fjmolinas mentioned this pull request Apr 25, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants