| 41 | } |
| 42 | |
| 43 | bool encrypt_hsm_secret(const struct secret *encryption_key, |
| 44 | const struct secret *hsm_secret, |
| 45 | struct encrypted_hsm_secret *output) |
| 46 | { |
| 47 | crypto_secretstream_xchacha20poly1305_state crypto_state; |
| 48 | |
| 49 | if (crypto_secretstream_xchacha20poly1305_init_push(&crypto_state, output->data, |
| 50 | encryption_key->data) != 0) |
| 51 | return false; |
| 52 | if (crypto_secretstream_xchacha20poly1305_push(&crypto_state, |
| 53 | output->data + HS_HEADER_LEN, |
| 54 | NULL, hsm_secret->data, |
| 55 | sizeof(hsm_secret->data), |
| 56 | /* Additional data and tag */ |
| 57 | NULL, 0, 0)) |
| 58 | return false; |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | bool decrypt_hsm_secret(const struct secret *encryption_key, |
| 64 | const struct encrypted_hsm_secret *cipher, |
no outgoing calls
no test coverage detected