Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update header parser in Secure Cell master key API #592

Merged
merged 9 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/themis/secure_cell_alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,21 @@
#define THEMIS_SYM_IV_LENGTH 16
#endif

static inline bool soter_alg_reserved_bits_valid(uint32_t alg)
{
static const uint32_t used_bits = SOTER_SYM_KEY_LENGTH_MASK | SOTER_SYM_PADDING_MASK
| SOTER_SYM_KDF_MASK | SOTER_SYM_ALG_MASK;
return (alg & ~used_bits) == 0;
}

static inline size_t soter_alg_key_length(uint32_t alg)
{
return (alg & SOTER_SYM_KEY_LENGTH_MASK) / 8;
Lagovas marked this conversation as resolved.
Show resolved Hide resolved
}

static inline uint32_t soter_alg_kdf(uint32_t alg)
{
return alg & SOTER_SYM_KDF_MASK;
}

#endif /* THEMIS_SECURE_CELL_ALG_H */
18 changes: 3 additions & 15 deletions src/themis/secure_cell_seal_passphrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static inline uint32_t soter_alg_without_kdf(uint32_t alg)

static inline size_t soter_alg_kdf_context_length(uint32_t alg)
{
switch (alg & SOTER_SYM_KDF_MASK) {
switch (soter_alg_kdf(alg)) {
case SOTER_SYM_PBKDF2:
return themis_scell_pbkdf2_context_min_size + THEMIS_AUTH_SYM_PBKDF2_SALT_LENGTH;
case SOTER_SYM_NOKDF:
Expand All @@ -47,18 +47,6 @@ static inline size_t soter_alg_kdf_context_length(uint32_t alg)
}
}

static inline size_t soter_alg_key_length(uint32_t alg)
{
return (alg & SOTER_SYM_KEY_LENGTH_MASK) / 8;
}

static inline bool soter_alg_reserved_bits_valid(uint32_t alg)
{
static const uint32_t used_bits = SOTER_SYM_KEY_LENGTH_MASK | SOTER_SYM_PADDING_MASK
| SOTER_SYM_KDF_MASK | SOTER_SYM_ALG_MASK;
return (alg & ~used_bits) == 0;
}

static inline size_t default_auth_token_size(void)
{
return themis_scell_auth_token_passphrase_min_size + THEMIS_AUTH_SYM_IV_LENGTH
Expand Down Expand Up @@ -137,7 +125,7 @@ static themis_status_t themis_auth_sym_derive_encryption_key(struct themis_scell
}
*derived_key_length = required_length;

switch (hdr->alg & SOTER_SYM_KDF_MASK) {
switch (soter_alg_kdf(hdr->alg)) {
case SOTER_SYM_PBKDF2:
return themis_auth_sym_derive_encryption_key_pbkdf2(hdr,
passphrase,
Expand Down Expand Up @@ -317,7 +305,7 @@ static themis_status_t themis_auth_sym_derive_decryption_key(
}
*derived_key_length = required_length;

switch (hdr->alg & SOTER_SYM_KDF_MASK) {
switch (soter_alg_kdf(hdr->alg)) {
case SOTER_SYM_PBKDF2:
return themis_auth_sym_derive_decryption_key_pbkdf2(hdr,
passphrase,
Expand Down
Loading