Skip to content
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
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ target_include_directories(eboot_hal PUBLIC ${EBLDR_INCLUDE_DIR})
# ---- Core boot logic ----
add_library(eboot_core STATIC
core/bootctl.c
core/boot_log.c
core/image_verify.c
core/slot_manager.c
core/boot_policy.c
Expand All @@ -107,10 +106,8 @@ add_library(eboot_core STATIC
core/os_adapter.c
core/ed25519_verify.c
core/sha512.c
core/secure_boot.c
core/fdt_loader.c
core/rollback.c
core/keystore.c
core/rollback.c
core/debug_lock.c
core/fw_decrypt.c
core/image_tlv.c
Expand Down
25 changes: 13 additions & 12 deletions core/ed25519_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "eos_types.h"
#include <string.h>


/* ================================================================
* Field arithmetic mod p = 2^255 - 19
* ================================================================ */
Expand Down Expand Up @@ -506,21 +507,21 @@ int eos_ed25519_verify(const uint8_t signature[64],
eos_sha512_final(&ctx, k);
reduce_hash(k);

/* Recompute R' = [S]B + [k](-A). A is already negated by unpackneg(), so
* the sum is R' rather than a difference. RFC 8032 permits the cheaper
* "compare encodings" check in place of a group-element comparison. */
gf lhs[4], rhs[4];
scalarmult(lhs, A, k);
scalarbase(rhs, &signature[32]);
point_add(lhs, (const gf *)rhs);
/* Compute [k](-A) + [S]B, which equals R for a valid signature. */
gf kA[4], sB[4];
scalarmult(kA, A, k);
scalarbase(sB, &signature[32]);
point_add(kA, (const gf *)sB);

uint8_t rcheck[32];
point_pack(rcheck, lhs);
uint8_t recovered[32];
point_pack(recovered, kA);

/* Constant-time comparison against R. */
uint8_t diff = 0;
for (int i = 0; i < 32; i++)
diff |= (uint8_t)(rcheck[i] ^ signature[i]);
for (int i = 0; i < 32; i++) diff |= (uint8_t)(recovered[i] ^ signature[i]);

/* Wipe the challenge scalar rather than leave it in boot-path memory. */
memset(k, 0, sizeof(k));


return diff == 0 ? EOS_OK : EOS_ERR_SIGNATURE;
}
2 changes: 1 addition & 1 deletion core/recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static int recovery_handle_write(eos_slot_t slot, uint32_t offset, uint16_t len)
/* offset/len come straight from the wire; without this check a
* recovery client can write past the slot boundary into the other
* slot, boot-control blocks, or the boot log. */
if (eos_recovery_write_in_range(base, slot_size, offset, len) != EOS_OK)
if (slot_size == 0 || (uint64_t)offset + len > (uint64_t)slot_size)
return recovery_send_nack();

recovery_send_ack();
Expand Down
Loading