Skip to content

Commit 5a650b4

Browse files
committed
[crypto] Expose hardened_xor function
As this function is useful also outside of keyblob, expose it. Signed-off-by: Pascal Nasahl <nasahlpa@lowrisc.org>
1 parent 0cfe3d9 commit 5a650b4

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

sw/device/lib/crypto/impl/keyblob.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,8 @@ status_t keyblob_from_key_and_mask(const uint32_t *key, const uint32_t *mask,
210210
return keyblob_from_shares(share0, mask, config, keyblob);
211211
}
212212

213-
/**
214-
* Combines two word buffers with XOR.
215-
*
216-
* Callers should ensure the entropy complex is up before calling this
217-
* function. The implementation uses random-order hardening primitives for
218-
* side-channel defense.
219-
*
220-
* @param[in,out] x Pointer to the first operand (modified in-place).
221-
* @param y Pointer to the second operand.
222-
* @param word_len Length in words of each operand.
223-
*/
224-
void hardened_xor(uint32_t *restrict x, const uint32_t *restrict y,
225-
size_t word_len) {
213+
status_t hardened_xor(uint32_t *restrict x, const uint32_t *restrict y,
214+
size_t word_len) {
226215
// Generate a random ordering.
227216
random_order_t order;
228217
random_order_init(&order, word_len);
@@ -267,6 +256,8 @@ void hardened_xor(uint32_t *restrict x, const uint32_t *restrict y,
267256
}
268257
RANDOM_ORDER_HARDENED_CHECK_DONE(order);
269258
HARDENED_CHECK_EQ(count, expected_count);
259+
260+
return OTCRYPTO_OK;
270261
}
271262

272263
status_t keyblob_remask(otcrypto_blinded_key_t *key) {

sw/device/lib/crypto/impl/keyblob.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ enum {
2424
kKeyblobHwBackedBytes = kKeyblobHwBackedWords * sizeof(uint32_t),
2525
};
2626

27+
/**
28+
* Combines two word buffers with XOR.
29+
*
30+
* Callers should ensure the entropy complex is up before calling this
31+
* function. The implementation uses random-order hardening primitives for
32+
* side-channel defense.
33+
*
34+
* @param[in,out] x Pointer to the first operand (modified in-place).
35+
* @param y Pointer to the second operand.
36+
* @param word_len Length in words of each operand.
37+
* @return Result of the operation.
38+
*/
39+
status_t hardened_xor(uint32_t *restrict x, const uint32_t *restrict y,
40+
size_t word_len);
41+
2742
/**
2843
* Get the word-length of the full blinded keyblob for a given key length.
2944
*

0 commit comments

Comments
 (0)