[openssh-commits] [openssh] 02/05: upstream: estructure sntrup761.sh to process all files in a single

git+noreply at mindrot.org git+noreply at mindrot.org
Fri Jan 8 13:50:54 AEDT 2021


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 91bac5e95b1b0debf9b2b4f05c20dcfa96b368b9
Author: dtucker at openbsd.org <dtucker at openbsd.org>
Date:   Mon Jan 4 21:58:58 2021 +0000

    upstream: estructure sntrup761.sh to process all files in a single
    
    list, which will make it easier to reorder.  Re-inline int32_MINMAX.  ok
    tobhe@
    
    OpenBSD-Commit-ID: d145c6c19b08bb93c9e14bfaa7af589d90f144c0
---
 int32_minmax.inc | 20 --------------------
 sntrup761.c      | 15 +++++++++++++--
 sntrup761.sh     | 39 ++++++++++++++++++++-------------------
 3 files changed, 33 insertions(+), 41 deletions(-)

diff --git a/int32_minmax.inc b/int32_minmax.inc
index 2f6ff519..e69de29b 100644
--- a/int32_minmax.inc
+++ b/int32_minmax.inc
@@ -1,20 +0,0 @@
-/*  $OpenBSD: int32_minmax.inc,v 1.1 2020/12/30 14:13:28 tobhe Exp $ */
-
-/*
- * Public Domain, Authors:
- * - Daniel J. Bernstein
- * - Chitchanok Chuengsatiansup
- * - Tanja Lange
- * - Christine van Vredendaal
- */
-
-#define int32_MINMAX(a,b) \
-do { \
-  int64_t ab = (int64_t)b ^ (int64_t)a; \
-  int64_t c = (int64_t)b - (int64_t)a; \
-  c ^= ab & (c ^ b); \
-  c >>= 31; \
-  c &= ab; \
-  a ^= c; \
-  b ^= c; \
-} while(0)
diff --git a/sntrup761.c b/sntrup761.c
index c7ef95c7..de18ca95 100644
--- a/sntrup761.c
+++ b/sntrup761.c
@@ -1,4 +1,4 @@
-/*  $OpenBSD: sntrup761.c,v 1.3 2021/01/03 18:05:21 tobhe Exp $ */
+/*  $OpenBSD: sntrup761.c,v 1.4 2021/01/04 21:58:58 dtucker Exp $ */
 
 /*
  * Public Domain, Authors:
@@ -12,10 +12,21 @@
 
 #include <string.h>
 #include "crypto_api.h"
-#include "int32_minmax.inc"
 
 #define CRYPTO_NAMESPACE(s) s
 
+/* from supercop-20201130/crypto_sort/int32/portable4/int32_minmax.inc */
+#define int32_MINMAX(a,b) \
+do { \
+  int64_t ab = (int64_t)b ^ (int64_t)a; \
+  int64_t c = (int64_t)b - (int64_t)a; \
+  c ^= ab & (c ^ b); \
+  c >>= 31; \
+  c &= ab; \
+  a ^= c; \
+  b ^= c; \
+} while(0)
+
 /* from supercop-20201130/crypto_sort/int32/portable4/sort.c */
 #define int32 crypto_int32
 
diff --git a/sntrup761.sh b/sntrup761.sh
index 3ab303ab..e7c5eed1 100644
--- a/sntrup761.sh
+++ b/sntrup761.sh
@@ -1,9 +1,12 @@
 #!/bin/sh
-#       $OpenBSD: sntrup761.sh,v 1.3 2021/01/03 18:05:21 tobhe Exp $
+#       $OpenBSD: sntrup761.sh,v 1.4 2021/01/04 21:58:58 dtucker Exp $
 #       Placed in the Public Domain.
 #
 AUTHOR="supercop-20201130/crypto_kem/sntrup761/ref/implementors"
 FILES="
+	supercop-20201130/crypto_sort/int32/portable4/int32_minmax.inc
+	supercop-20201130/crypto_sort/int32/portable4/sort.c
+	supercop-20201130/crypto_sort/uint32/useint32/sort.c
 	supercop-20201130/crypto_kem/sntrup761/ref/uint64.h
 	supercop-20201130/crypto_kem/sntrup761/ref/uint16.h
 	supercop-20201130/crypto_kem/sntrup761/ref/uint32.h
@@ -20,10 +23,6 @@ FILES="
 	supercop-20201130/crypto_kem/sntrup761/ref/Encode.c
 	supercop-20201130/crypto_kem/sntrup761/ref/kem.c
 "
-SORT_I32="
-	supercop-20201130/crypto_sort/int32/portable4/sort.c
-"
-SORT_U32="supercop-20201130/crypto_sort/uint32/useint32/sort.c"
 ###
 
 set -e
@@ -38,29 +37,31 @@ echo ' */'
 echo
 echo '#include <string.h>'
 echo '#include "crypto_api.h"'
-echo '#include "int32_minmax.inc"'
 echo
 echo '#define CRYPTO_NAMESPACE(s) s'
 echo
-for i in $SORT_I32; do
-	echo "/* from $i */"
-	grep \
-	   -v '#include' $i | \
-	   sed -e "s/void crypto_sort/static void crypto_sort_int32/g"
-	echo
-done
-echo "/* from $SORT_U32 */"
-grep \
-   -v '#include' $SORT_U32 | \
-   sed -e "s/void crypto_sort/static void crypto_sort_uint32/g"
-echo
 for i in $FILES; do
 	echo "/* from $i */"
 	grep \
 	   -v '#include' $i | \
-	   sed -e "s/crypto_kem_/crypto_kem_sntrup761_/g" \
+	case "$i" in
+	# Use int64_t for intermediate values in int32_MINMAX to prevent signed
+	# 32-bit integer overflow when called by crypto_sort_uint32.
+	*/int32_minmax.inc)
+	    sed -e "s/int32 ab = b ^ a/int64_t ab = (int64_t)b ^ (int64_t)a/" \
+	    -e "s/int32 c = b - a/int64_t c = (int64_t)b - (int64_t)a/"
+	    ;;
+	*/int32/portable4/sort.c)
+	    sed -e "s/void crypto_sort/static void crypto_sort_int32/g"
+	    ;;
+	*/uint32/useint32/sort.c)
+	    sed -e "s/void crypto_sort/static void crypto_sort_uint32/g"
+	    ;;
+	*)
+	    sed -e "s/crypto_kem_/crypto_kem_sntrup761_/g" \
 		-e "s/^extern void /static void /" \
 		-e "s/^void /static void /" \
 		-e "/^typedef int32_t int32;$/d"
+	esac
 	echo
 done

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list