Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3ceecbc

Browse files
committed
apply patch for sntrup761x25519-sha512@openssh.com
enable sntrup761-x25519
1 parent c1a8d54 commit 3ceecbc

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

‎contrib/win32/openssh/config.h.vs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,3 +1767,5 @@
17671767
#define HAVE_EVP_PKEY_GET0_RSA 1
17681768
#define HAVE_EVP_MD_CTX_NEW 1
17691769
#define HAVE_EVP_MD_CTX_FREE 1
1770+
1771+
#define USE_SNTRUP761X25519 1

‎myproposal.h‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,6 @@
2424
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27-
#ifdef WINDOWS
28-
// these should be in the same order as upstream, without the ones we don't support
29-
#define KEX_SERVER_KEX \
30-
"curve25519-sha256," \
31-
"curve25519-sha256@libssh.org," \
32-
"ecdh-sha2-nistp256," \
33-
"ecdh-sha2-nistp384," \
34-
"ecdh-sha2-nistp521," \
35-
"diffie-hellman-group-exchange-sha256," \
36-
"diffie-hellman-group16-sha512," \
37-
"diffie-hellman-group18-sha512," \
38-
"diffie-hellman-group14-sha256"
39-
#else
4027
#define KEX_SERVER_KEX \
4128
"sntrup761x25519-sha512@openssh.com," \
4229
"curve25519-sha256," \
@@ -48,7 +35,6 @@
4835
"diffie-hellman-group16-sha512," \
4936
"diffie-hellman-group18-sha512," \
5037
"diffie-hellman-group14-sha256"
51-
#endif
5238

5339
#define KEX_CLIENT_KEX KEX_SERVER_KEX
5440

‎sntrup761.c‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include <string.h>
1616
#include "crypto_api.h"
1717

18+
#ifdef WINDOWS
19+
#include "xmalloc.h"
20+
#endif /* WINDOWS */
21+
1822
#define int8 crypto_int8
1923
#define uint8 crypto_uint8
2024
#define int16 crypto_int16
@@ -296,11 +300,25 @@ static void Decode(uint16 *out,const unsigned char *S,const uint16 *M,long long
296300
else
297301
*out = uint32_mod_uint14(S[0]+(((uint16)S[1])<<8),M[0]);
298302
}
303+
#ifdef WINDOWS
304+
uint16_t *R2 = NULL, *M2 = NULL, *bottomr = NULL;
305+
uint32_t *bottomt = NULL;
306+
size_t MR_len = 0, bottom_len = 0;
307+
#endif /* WINDOWS */
299308
if (len > 1) {
309+
#ifdef WINDOWS
310+
MR_len = (len + 1) / 2;
311+
bottom_len = len / 2;
312+
R2 = xcalloc(MR_len, sizeof(*R2));
313+
M2 = xcalloc(MR_len, sizeof(*M2));
314+
bottomr = xcalloc(bottom_len, sizeof(*bottomr));
315+
bottomt = xcalloc(bottom_len, sizeof(*bottomt));
316+
#else
300317
uint16 R2[(len+1)/2];
301318
uint16 M2[(len+1)/2];
302319
uint16 bottomr[len/2];
303320
uint32 bottomt[len/2];
321+
#endif /* WINDOWS */
304322
long long i;
305323
for (i = 0;i < len-1;i += 2) {
306324
uint32 m = M[i]*(uint32) M[i+1];
@@ -336,6 +354,12 @@ static void Decode(uint16 *out,const unsigned char *S,const uint16 *M,long long
336354
if (i < len)
337355
*out++ = R2[i/2];
338356
}
357+
#ifdef WINDOWS
358+
freezero(R2, MR_len * sizeof(*R2));
359+
freezero(M2, MR_len * sizeof(*M2));
360+
freezero(bottomr, bottom_len * sizeof(*bottomr));
361+
freezero(bottomt, bottom_len * sizeof(*bottomt));
362+
#endif /* WINDOWS */
339363
}
340364

341365
/* from supercop-20201130/crypto_kem/sntrup761/ref/Encode.h */
@@ -362,9 +386,19 @@ static void Encode(unsigned char *out,const uint16 *R,const uint16 *M,long long
362386
m = (m+255)>>8;
363387
}
364388
}
389+
#ifdef WINDOWS
390+
uint16_t *R2 = NULL, *M2 = NULL;
391+
size_t MR_len = 0;
392+
#endif /* WINDOWS */
365393
if (len > 1) {
394+
#ifdef WINDOWS
395+
MR_len = (len + 1) / 2;
396+
R2 = xcalloc(MR_len, sizeof(*R2));
397+
M2 = xcalloc(MR_len, sizeof(*M2));
398+
#else
366399
uint16 R2[(len+1)/2];
367400
uint16 M2[(len+1)/2];
401+
#endif /* WINDOWS */
368402
long long i;
369403
for (i = 0;i < len-1;i += 2) {
370404
uint32 m0 = M[i];
@@ -384,6 +418,10 @@ static void Encode(unsigned char *out,const uint16 *R,const uint16 *M,long long
384418
}
385419
Encode(out,R2,M2,(len+1)/2);
386420
}
421+
#ifdef WINDOWS
422+
freezero(R2, MR_len * sizeof(*R2));
423+
freezero(M2, MR_len * sizeof(*M2));
424+
#endif /* WINDOWS */
387425
}
388426

389427
/* from supercop-20201130/crypto_kem/sntrup761/ref/kem.c */
@@ -685,14 +723,22 @@ static void Short_fromlist(small *out,const uint32 *in)
685723
/* e.g., b = 0 means out = Hash0(in) */
686724
static void Hash_prefix(unsigned char *out,int b,const unsigned char *in,int inlen)
687725
{
726+
#ifdef WINDOWS
727+
unsigned char* x;
728+
x = xcalloc(inlen + 1, sizeof(*x));
729+
#else
688730
unsigned char x[inlen+1];
731+
#endif /* WINDOWS */
689732
unsigned char h[64];
690733
int i;
691734

692735
x[0] = b;
693736
for (i = 0;i < inlen;++i) x[i+1] = in[i];
694737
crypto_hash_sha512(h,x,inlen+1);
695738
for (i = 0;i < 32;++i) out[i] = h[i];
739+
#ifdef WINDOWS
740+
freezero(x, (inlen + 1) * sizeof(*x));
741+
#endif /* WINDOWS */
696742
}
697743

698744
/* ----- higher-level randomness */

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /