From 48cceb63c432b172063a0b427248db7f6c64f044 Mon Sep 17 00:00:00 2001 From: sublime-elephant Date: Thu, 12 Mar 2026 20:13:39 +1100 Subject: [PATCH] Explicit uint32_t cast for crypto1 state calculations Platforms where the standard C int data-type is only 16 bits wide will fail initialising a correct Crypto1 state. Explicitly casting the keystream bit to 32 bits fixes this issue. --- src/crypto1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto1.c b/src/crypto1.c index 121cca5..5421e78 100644 --- a/src/crypto1.c +++ b/src/crypto1.c @@ -67,7 +67,7 @@ uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted) uint8_t i, ret = 0; for (i = 0; i < 8; ++i) - ret |= crypto1_bit(s, BIT(in, i), is_encrypted) << i; + ret |= ((uint32_t)crypto1_bit(s, BIT(in, i), is_encrypted)) << i; return ret; } @@ -76,7 +76,7 @@ uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted) uint32_t i, ret = 0; for (i = 0; i < 32; ++i) - ret |= crypto1_bit(s, BEBIT(in, i), is_encrypted) << (i ^ 24); + ret |= ((uint32_t)crypto1_bit(s, BEBIT(in, i), is_encrypted)) << (i ^ 24); return ret; }