Ticket #13280: 0002-Allow-unsafe-left-shifts-in-ed25519-using-DUNSAFE_SI.patch

File 0002-Allow-unsafe-left-shifts-in-ed25519-using-DUNSAFE_SI.patch, 2.9 KB (added by teor, 5 years ago)

Add -DUNSAFE_SIGNED_LSHIFT to revert to old behaviour and code

  • changes/bug13280-ed25519-signed-left-shift-overflow

    From 5859a1d01dfbd8d37987330a6c22a7744450ed8e Mon Sep 17 00:00:00 2001
    From: teor <teor2345@gmail.com>
    Date: Mon, 29 Sep 2014 03:11:30 +1000
    Subject: [PATCH 2/2] Allow unsafe left shifts in ed25519 using
     -DUNSAFE_SIGNED_LSHIFT
    
    Verify the ed25519 changes by diffing:
    cpp -E -DUNSAFE_SIGNED_LSHIFT new_file.c
    cpp -E old_file.c
    Result: whitespace, line number, and (non-significant) bracket changes.
    ---
     changes/bug13280-ed25519-signed-left-shift-overflow |  2 +-
     src/ext/ed25519/ref10/crypto_int32.h                | 10 ++++++++--
     src/ext/ed25519/ref10/crypto_int64.h                | 10 ++++++++--
     3 files changed, 17 insertions(+), 5 deletions(-)
    
    diff --git a/changes/bug13280-ed25519-signed-left-shift-overflow b/changes/bug13280-ed25519-signed-left-shift-overflow
    index 190022c..ad05e9f 100644
    a b  
    11  o Minor bugfixes:
    2     - Avoid signed left shift overflows in ed25519 arithmetic 
     2    - Avoid signed left shift overflows in ed25519 arithmetic
    33      using unsigned bitwise operations. Fixes bug 13280.
  • src/ext/ed25519/ref10/crypto_int32.h

    diff --git a/src/ext/ed25519/ref10/crypto_int32.h b/src/ext/ed25519/ref10/crypto_int32.h
    index 46a2a2b..cb7c002 100644
    a b  
    55
    66#include "torint.h"
    77#define crypto_int32 int32_t
    8 #define crypto_uint32 uint32_t
    98
    109/*
    1110 Stop signed left shifts overflowing
    1211 by using unsigned types for bitwise operations
    13  */
     12*/
    1413
    1514#ifndef OVERFLOW_SAFE_SIGNED_LSHIFT
    1615#define OVERFLOW_SAFE_SIGNED_LSHIFT(s, lshift, utype, stype) \
    1716  ((stype)((utype)(s) << (utype)(lshift)))
    1817#endif
    1918
     19#include "crypto_uint32.h"
     20
     21#ifdef UNSAFE_SIGNED_LSHIFT
     22/* the original version of the code */
     23#define SHL32(s, lshift) s << lshift
     24#else /* #ifndef UNSAFE_SIGNED_LSHIFT */
    2025#define SHL32(s, lshift) \
    2126  OVERFLOW_SAFE_SIGNED_LSHIFT(s, lshift, crypto_uint32, crypto_int32)
     27#endif /* UNSAFE_SIGNED_LSHIFT */
    2228
    2329#endif /* CRYPTO_INT32_H */
  • src/ext/ed25519/ref10/crypto_int64.h

    diff --git a/src/ext/ed25519/ref10/crypto_int64.h b/src/ext/ed25519/ref10/crypto_int64.h
    index 46e8852..5db0446 100644
    a b  
    55
    66#include "torint.h"
    77#define crypto_int64 int64_t
    8 #define crypto_uint64 uint64_t
    98
    109/*
    1110 Stop signed left shifts overflowing
    1211 by using unsigned types for bitwise operations
    13  */
     12*/
    1413
    1514#ifndef OVERFLOW_SAFE_SIGNED_LSHIFT
    1615#define OVERFLOW_SAFE_SIGNED_LSHIFT(s, lshift, utype, stype) \
    1716  ((stype)((utype)(s) << (utype)(lshift)))
    1817#endif
    1918
     19#include "crypto_uint64.h"
     20
     21#ifdef UNSAFE_SIGNED_LSHIFT
     22/* the original version of the code */
     23#define SHL64(s, lshift) s << lshift
     24#else /* #ifndef UNSAFE_SIGNED_LSHIFT */
    2025#define SHL64(s, lshift) \
    2126  OVERFLOW_SAFE_SIGNED_LSHIFT(s, lshift, crypto_uint64, crypto_int64)
     27#endif /* UNSAFE_SIGNED_LSHIFT */
    2228
    2329#endif /* CRYPTO_INT64_H */