@@ -49,9 +49,9 @@ CDoc2Writer::writeHeader(const std::vector<libcdoc::Recipient> &recipients)
4949 return libcdoc::WRONG_ARGUMENTS;
5050 }
5151 std::vector<uint8_t > rnd;
52- if (auto rv = crypto->random (rnd, libcdoc::CDoc2 ::KEY_LEN); rv < 0 )
52+ if (auto rv = crypto->random (rnd, libcdoc::CDoc2Internal ::KEY_LEN); rv < 0 )
5353 return rv;
54- std::vector<uint8_t > fmk = libcdoc::Crypto::extract (rnd, {libcdoc::CDoc2 ::SALT.cbegin (), libcdoc::CDoc2 ::SALT.cend ()});
54+ std::vector<uint8_t > fmk = libcdoc::Crypto::extract (rnd, {libcdoc::CDoc2Internal ::SALT.cbegin (), libcdoc::CDoc2Internal ::SALT.cend ()});
5555 std::fill (rnd.begin (), rnd.end (), 0 );
5656 LOG_TRACE_KEY (" fmk: {}" , fmk);
5757
@@ -62,8 +62,8 @@ CDoc2Writer::writeHeader(const std::vector<libcdoc::Recipient> &recipients)
6262 return rv;
6363 }
6464
65- auto hhk = libcdoc::Crypto::expand (fmk, libcdoc::CDoc2 ::HMAC);
66- auto cek = libcdoc::Crypto::expand (fmk, libcdoc::CDoc2 ::CEK);
65+ auto hhk = libcdoc::Crypto::expand (fmk, libcdoc::CDoc2Internal ::HMAC);
66+ auto cek = libcdoc::Crypto::expand (fmk, libcdoc::CDoc2Internal ::CEK);
6767 std::fill (fmk.begin (), fmk.end (), 0 );
6868 LOG_TRACE_KEY (" cek: {}" , cek);
6969 LOG_TRACE_KEY (" hhk: {}" , hhk);
@@ -75,16 +75,16 @@ CDoc2Writer::writeHeader(const std::vector<libcdoc::Recipient> &recipients)
7575 // FIXME: not big/little endian friendly
7676 uint8_t header_len[] {uint8_t (hs >> 24 ), uint8_t ((hs >> 16 ) & 0xff ), uint8_t ((hs >> 8 ) & 0xff ), uint8_t (hs & 0xff )};
7777
78- dst->write ((const uint8_t *) libcdoc::CDoc2 ::LABEL.data (), libcdoc::CDoc2 ::LABEL.size ());
78+ dst->write ((const uint8_t *) libcdoc::CDoc2Internal ::LABEL.data (), libcdoc::CDoc2Internal ::LABEL.size ());
7979 dst->write ((const uint8_t *) &header_len, 4 );
8080 dst->write (header.data (), header.size ());
8181 dst->write (headerHMAC.data (), headerHMAC.size ());
8282
8383 std::vector<uint8_t > nonce;
84- crypto->random (nonce, libcdoc::CDoc2 ::NONCE_LEN);
84+ crypto->random (nonce, libcdoc::CDoc2Internal ::NONCE_LEN);
8585 LOG_TRACE_KEY (" nonce: {}" , nonce);
8686 auto cipher = std::make_unique<EncryptionConsumer>(*dst, EVP_chacha20_poly1305 (), Crypto::Key (std::move (cek), nonce));
87- std::vector<uint8_t > aad (libcdoc::CDoc2 ::PAYLOAD.cbegin (), libcdoc::CDoc2 ::PAYLOAD.cend ());
87+ std::vector<uint8_t > aad (libcdoc::CDoc2Internal ::PAYLOAD.cbegin (), libcdoc::CDoc2Internal ::PAYLOAD.cend ());
8888 aad.insert (aad.end (), header.cbegin (), header.cend ());
8989 aad.insert (aad.end (), headerHMAC.cbegin (), headerHMAC.cend ());
9090 if (auto rv = cipher->writeAAD (aad); rv < 0 )
@@ -198,7 +198,7 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
198198 flatbuffers::FlatBufferBuilder builder;
199199 std::vector<flatbuffers::Offset<cdoc20::header::RecipientRecord>> fb_rcpts;
200200
201- std::vector<uint8_t > xor_key (libcdoc::CDoc2 ::KEY_LEN);
201+ std::vector<uint8_t > xor_key (libcdoc::CDoc2Internal ::KEY_LEN);
202202 for (unsigned int rcpt_idx = 0 ; rcpt_idx < recipients.size (); rcpt_idx++) {
203203 const libcdoc::Recipient& rcpt = recipients.at (rcpt_idx);
204204 if (rcpt.isPKI ()) {
@@ -223,7 +223,7 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
223223 }
224224 }
225225 if (rcpt.pk_type == libcdoc::Recipient::PKType::RSA) {
226- crypto->random (kek, libcdoc::CDoc2 ::KEY_LEN);
226+ crypto->random (kek, libcdoc::CDoc2Internal ::KEY_LEN);
227227 if (libcdoc::Crypto::xor_data (xor_key, fmk, kek) != libcdoc::OK) {
228228 setLastError (" Internal error" );
229229 LOG_ERROR (" {}" , last_error);
@@ -267,8 +267,8 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
267267 auto ephKey = libcdoc::Crypto::genECKey (publicKey.get ());
268268 std::vector<uint8_t > sharedSecret = libcdoc::Crypto::deriveSharedSecret (ephKey.get (), publicKey.get ());
269269 key_material = libcdoc::Crypto::toPublicKeyDer (ephKey.get ());
270- std::vector<uint8_t > kekPm = libcdoc::Crypto::extract (sharedSecret, std::vector<uint8_t >(libcdoc::CDoc2 ::KEKPREMASTER.cbegin (), libcdoc::CDoc2 ::KEKPREMASTER.cend ()));
271- std::string info_str = libcdoc::CDoc2 ::getSaltForExpand (key_material, rcpt.rcpt_key );
270+ std::vector<uint8_t > kekPm = libcdoc::Crypto::extract (sharedSecret, std::vector<uint8_t >(libcdoc::CDoc2Internal ::KEKPREMASTER.cbegin (), libcdoc::CDoc2Internal ::KEKPREMASTER.cend ()));
271+ std::string info_str = libcdoc::CDoc2Internal ::getSaltForExpand (key_material, rcpt.rcpt_key );
272272
273273 kek = libcdoc::Crypto::expand (kekPm, info_str, fmk.size ());
274274 if (libcdoc::Crypto::xor_data (xor_key, fmk, kek) != libcdoc::OK) {
@@ -302,16 +302,16 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
302302 }
303303 }
304304 } else if (rcpt.isSymmetric ()) {
305- std::string info_str = libcdoc::CDoc2 ::getSaltForExpand (rcpt.getLabel ({}));
306- std::vector<uint8_t > kek_pm (libcdoc::CDoc2 ::KEY_LEN);
305+ std::string info_str = libcdoc::CDoc2Internal ::getSaltForExpand (rcpt.getLabel ({}));
306+ std::vector<uint8_t > kek_pm (libcdoc::CDoc2Internal ::KEY_LEN);
307307 std::vector<uint8_t > salt;
308- int64_t result = crypto->random (salt, libcdoc::CDoc2 ::KEY_LEN);
308+ int64_t result = crypto->random (salt, libcdoc::CDoc2Internal ::KEY_LEN);
309309 if (result < 0 ) {
310310 setLastError (crypto->getLastErrorStr (result));
311311 return result;
312312 }
313313 std::vector<uint8_t > pw_salt;
314- result = crypto->random (pw_salt, libcdoc::CDoc2 ::KEY_LEN);
314+ result = crypto->random (pw_salt, libcdoc::CDoc2Internal ::KEY_LEN);
315315 if (result < 0 ) {
316316 setLastError (crypto->getLastErrorStr (result));
317317 return result;
@@ -321,7 +321,7 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
321321 setLastError (crypto->getLastErrorStr (result));
322322 return result;
323323 }
324- std::vector<uint8_t > kek = libcdoc::Crypto::expand (kek_pm, info_str, libcdoc::CDoc2 ::KEY_LEN);
324+ std::vector<uint8_t > kek = libcdoc::Crypto::expand (kek_pm, info_str, libcdoc::CDoc2Internal ::KEY_LEN);
325325
326326 LOG_DBG (" Label: {}" , rcpt.label );
327327 LOG_DBG (" KDF iter: {}" , rcpt.kdf_iter );
@@ -368,11 +368,11 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
368368 // # KEK_i computation:
369369 // KeyMaterialSalt_i = CSRNG(256)
370370 std::vector<uint8_t > key_material_salt;
371- crypto->random (key_material_salt, libcdoc::CDoc2 ::KEY_LEN);
371+ crypto->random (key_material_salt, libcdoc::CDoc2Internal ::KEY_LEN);
372372
373373 // KeyMaterial_i = CSRNG(256)
374374 std::vector<uint8_t > key_material;
375- crypto->random (key_material, libcdoc::CDoc2 ::KEY_LEN);
375+ crypto->random (key_material, libcdoc::CDoc2Internal ::KEY_LEN);
376376
377377 // KEK_i_pm = HKDF_Extract(KeyMaterialSalt_i, KeyMaterial_i)
378378 std::vector<uint8_t > kek_pm = libcdoc::Crypto::extract (key_material_salt, key_material);
@@ -394,7 +394,7 @@ CDoc2Writer::buildHeader(std::vector<uint8_t>& header, const std::vector<libcdoc
394394 std::vector<std::vector<uint8_t >> kek_shares (N_SHARES);
395395 for (int i = 1 ; i < N_SHARES; i++) {
396396 // KEK_i_share_j = CSRNG(256)
397- crypto->random (kek_shares[i], libcdoc::CDoc2 ::KEY_LEN);
397+ crypto->random (kek_shares[i], libcdoc::CDoc2Internal ::KEY_LEN);
398398 }
399399 // KEK_i_share_1 = XOR(KEK_i, KEK_i_share_2, KEK_i_share_3,..., KEK_i_share_n)
400400 kek_shares[0 ] = std::move (kek);
0 commit comments