Module Name: src
Committed By: rin
Date: Tue Oct 29 03:20:32 UTC 2024
Modified Files:
src/crypto/external/bsd/openssh/dist: kexmlkem768x25519.c
libcrux_mlkem768_sha3.h mlkem768.sh
Log Message:
openssh: Fix mlkem768x25519-sha256 KEX algorithm for big-endian machines
Tested for macppc.
This KEX algorithm has been added to OpenSSH 9.9, and no release
branches are affected.
Cherry-picked from upstream:
(1/2) https://github.com/openbsd/src/commit/66207d7b19f
fix ML-KEM768x25519 KEX on big-endian systems;
spotted by jsg@ feedback/ok deraadt@
(2/2) https://github.com/openbsd/src/commit/c42fee07eda
explicitly include endian.h
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/crypto/external/bsd/openssh/dist/kexmlkem768x25519.c
cvs rdiff -u -r1.1.1.1 -r1.2 \
src/crypto/external/bsd/openssh/dist/libcrux_mlkem768_sha3.h \
src/crypto/external/bsd/openssh/dist/mlkem768.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/crypto/external/bsd/openssh/dist/kexmlkem768x25519.c
diff -u src/crypto/external/bsd/openssh/dist/kexmlkem768x25519.c:1.2 src/crypto/external/bsd/openssh/dist/kexmlkem768x25519.c:1.3
--- src/crypto/external/bsd/openssh/dist/kexmlkem768x25519.c:1.2 Tue Sep 24 21:32:18 2024
+++ src/crypto/external/bsd/openssh/dist/kexmlkem768x25519.c Tue Oct 29 03:20:32 2024
@@ -1,5 +1,5 @@
-/* $NetBSD: kexmlkem768x25519.c,v 1.2 2024/09/24 21:32:18 christos Exp $ */
-/* $OpenBSD: kexmlkem768x25519.c,v 1.1 2024/09/02 12:13:56 djm Exp $ */
+/* $NetBSD: kexmlkem768x25519.c,v 1.3 2024/10/29 03:20:32 rin Exp $ */
+/* $OpenBSD: kexmlkem768x25519.c,v 1.2 2024/10/27 02:06:59 djm Exp $ */
/*
* Copyright (c) 2023 Markus Friedl. All rights reserved.
*
@@ -24,7 +24,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
-__RCSID("$NetBSD: kexmlkem768x25519.c,v 1.2 2024/09/24 21:32:18 christos Exp $");
+__RCSID("$NetBSD: kexmlkem768x25519.c,v 1.3 2024/10/29 03:20:32 rin Exp $");
#include <sys/types.h>
@@ -33,6 +33,7 @@ __RCSID("$NetBSD: kexmlkem768x25519.c,v
#include <stdbool.h>
#include <string.h>
#include <signal.h>
+#include <endian.h>
#include "sshkey.h"
#include "kex.h"
Index: src/crypto/external/bsd/openssh/dist/libcrux_mlkem768_sha3.h
diff -u src/crypto/external/bsd/openssh/dist/libcrux_mlkem768_sha3.h:1.1.1.1 src/crypto/external/bsd/openssh/dist/libcrux_mlkem768_sha3.h:1.2
--- src/crypto/external/bsd/openssh/dist/libcrux_mlkem768_sha3.h:1.1.1.1 Tue Sep 24 21:28:09 2024
+++ src/crypto/external/bsd/openssh/dist/libcrux_mlkem768_sha3.h Tue Oct 29 03:20:32 2024
@@ -1,4 +1,5 @@
-/* $OpenBSD: libcrux_mlkem768_sha3.h,v 1.1 2024/09/02 12:13:56 djm Exp $ */
+/* $OpenBSD: libcrux_mlkem768_sha3.h,v 1.2 2024/10/27 02:06:01 djm Exp $ */
+
/* Extracted from libcrux revision 84c5d87b3092c59294345aa269ceefe0eb97cc35 */
/*
@@ -160,18 +161,19 @@ static inline void Eurydice_slice_to_arr
// CORE STUFF (conversions, endianness, ...)
static inline void core_num__u64_9__to_le_bytes(uint64_t v, uint8_t buf[8]) {
+ v = htole64(v);
memcpy(buf, &v, sizeof(v));
}
static inline uint64_t core_num__u64_9__from_le_bytes(uint8_t buf[8]) {
uint64_t v;
memcpy(&v, buf, sizeof(v));
- return v;
+ return le64toh(v);
}
static inline uint32_t core_num__u32_8__from_le_bytes(uint8_t buf[4]) {
uint32_t v;
memcpy(&v, buf, sizeof(v));
- return v;
+ return le32toh(v);
}
static inline uint32_t core_num__u8_6__count_ones(uint8_t x0) {
Index: src/crypto/external/bsd/openssh/dist/mlkem768.sh
diff -u src/crypto/external/bsd/openssh/dist/mlkem768.sh:1.1.1.1 src/crypto/external/bsd/openssh/dist/mlkem768.sh:1.2
--- src/crypto/external/bsd/openssh/dist/mlkem768.sh:1.1.1.1 Tue Sep 24 21:28:09 2024
+++ src/crypto/external/bsd/openssh/dist/mlkem768.sh Tue Oct 29 03:20:32 2024
@@ -1,9 +1,10 @@
#!/bin/sh
-# $OpenBSD: mlkem768.sh,v 1.2 2024/09/04 05:11:33 djm Exp $
+# $OpenBSD: mlkem768.sh,v 1.3 2024/10/27 02:06:01 djm Exp $
# Placed in the Public Domain.
#
-WANT_LIBCRUX_REVISION="origin/main"
+#WANT_LIBCRUX_REVISION="origin/main"
+WANT_LIBCRUX_REVISION="84c5d87b3092c59294345aa269ceefe0eb97cc35"
FILES="
libcrux/libcrux-ml-kem/cg/eurydice_glue.h
@@ -47,6 +48,7 @@ echo '#define KRML_NOINLINE __attribute_
echo '#define KRML_HOST_EPRINTF(...)'
echo '#define KRML_HOST_EXIT(x) fatal_f("internal error")'
echo
+
for i in $FILES; do
echo "/* from $i */"
# Changes to all files:
@@ -56,11 +58,16 @@ for i in $FILES; do
-e 's/[ ]*$//' \
$i | \
case "$i" in
- # XXX per-file handling goes here.
+ */libcrux-ml-kem/cg/eurydice_glue.h)
+ # Replace endian functions with versions that work.
+ perl -0777 -pe 's/(static inline void core_num__u64_9__to_le_bytes.*\n)([^}]*\n)/\1 v = htole64(v);\n\2/' |
+ perl -0777 -pe 's/(static inline uint64_t core_num__u64_9__from_le_bytes.*?)return v;/\1return le64toh(v);/s' |
+ perl -0777 -pe 's/(static inline uint32_t core_num__u32_8__from_le_bytes.*?)return v;/\1return le32toh(v);/s'
+ ;;
# Default: pass through.
*)
- cat
- ;;
+ cat
+ ;;
esac
echo
done