1- /* $OpenBSD: kexsntrup4591761x25519 .c,v 1.4 2020/12/19 22:09:21 tobhe Exp $ */
1+ /* $OpenBSD: kexsntrup761x25519 .c,v 1.1 2020/12/29 00:59:15 djm Exp $ */
22/*
33 * Copyright (c) 2019 Markus Friedl. All rights reserved.
44 *
3636#include "ssherr.h"
3737
3838int
39- kex_kem_sntrup4591761x25519_keypair (struct kex * kex )
39+ kex_kem_sntrup761x25519_keypair (struct kex * kex )
4040{
4141 struct sshbuf * buf = NULL ;
4242 u_char * cp = NULL ;
@@ -45,15 +45,15 @@ kex_kem_sntrup4591761x25519_keypair(struct kex *kex)
4545
4646 if ((buf = sshbuf_new ()) == NULL )
4747 return SSH_ERR_ALLOC_FAIL ;
48- need = crypto_kem_sntrup4591761_PUBLICKEYBYTES + CURVE25519_SIZE ;
48+ need = crypto_kem_sntrup761_PUBLICKEYBYTES + CURVE25519_SIZE ;
4949 if ((r = sshbuf_reserve (buf , need , & cp )) != 0 )
5050 goto out ;
51- crypto_kem_sntrup4591761_keypair (cp , kex -> sntrup4591761_client_key );
51+ crypto_kem_sntrup761_keypair (cp , kex -> sntrup761_client_key );
5252#ifdef DEBUG_KEXECDH
53- dump_digest ("client public key sntrup4591761 :" , cp ,
54- crypto_kem_sntrup4591761_PUBLICKEYBYTES );
53+ dump_digest ("client public key sntrup761 :" , cp ,
54+ crypto_kem_sntrup761_PUBLICKEYBYTES );
5555#endif
56- cp += crypto_kem_sntrup4591761_PUBLICKEYBYTES ;
56+ cp += crypto_kem_sntrup761_PUBLICKEYBYTES ;
5757 kexc25519_keygen (kex -> c25519_client_key , cp );
5858#ifdef DEBUG_KEXECDH
5959 dump_digest ("client public key c25519:" , cp , CURVE25519_SIZE );
@@ -66,7 +66,7 @@ kex_kem_sntrup4591761x25519_keypair(struct kex *kex)
6666}
6767
6868int
69- kex_kem_sntrup4591761x25519_enc (struct kex * kex ,
69+ kex_kem_sntrup761x25519_enc (struct kex * kex ,
7070 const struct sshbuf * client_blob , struct sshbuf * * server_blobp ,
7171 struct sshbuf * * shared_secretp )
7272{
@@ -83,17 +83,17 @@ kex_kem_sntrup4591761x25519_enc(struct kex *kex,
8383 * shared_secretp = NULL ;
8484
8585 /* client_blob contains both KEM and ECDH client pubkeys */
86- need = crypto_kem_sntrup4591761_PUBLICKEYBYTES + CURVE25519_SIZE ;
86+ need = crypto_kem_sntrup761_PUBLICKEYBYTES + CURVE25519_SIZE ;
8787 if (sshbuf_len (client_blob ) != need ) {
8888 r = SSH_ERR_SIGNATURE_INVALID ;
8989 goto out ;
9090 }
9191 client_pub = sshbuf_ptr (client_blob );
9292#ifdef DEBUG_KEXECDH
93- dump_digest ("client public key sntrup4591761 :" , client_pub ,
94- crypto_kem_sntrup4591761_PUBLICKEYBYTES );
93+ dump_digest ("client public key sntrup761 :" , client_pub ,
94+ crypto_kem_sntrup761_PUBLICKEYBYTES );
9595 dump_digest ("client public key 25519:" ,
96- client_pub + crypto_kem_sntrup4591761_PUBLICKEYBYTES ,
96+ client_pub + crypto_kem_sntrup761_PUBLICKEYBYTES ,
9797 CURVE25519_SIZE );
9898#endif
9999 /* allocate buffer for concatenation of KEM key and ECDH shared key */
@@ -102,32 +102,32 @@ kex_kem_sntrup4591761x25519_enc(struct kex *kex,
102102 r = SSH_ERR_ALLOC_FAIL ;
103103 goto out ;
104104 }
105- if ((r = sshbuf_reserve (buf , crypto_kem_sntrup4591761_BYTES ,
105+ if ((r = sshbuf_reserve (buf , crypto_kem_sntrup761_BYTES ,
106106 & kem_key )) != 0 )
107107 goto out ;
108108 /* allocate space for encrypted KEM key and ECDH pub key */
109109 if ((server_blob = sshbuf_new ()) == NULL ) {
110110 r = SSH_ERR_ALLOC_FAIL ;
111111 goto out ;
112112 }
113- need = crypto_kem_sntrup4591761_CIPHERTEXTBYTES + CURVE25519_SIZE ;
113+ need = crypto_kem_sntrup761_CIPHERTEXTBYTES + CURVE25519_SIZE ;
114114 if ((r = sshbuf_reserve (server_blob , need , & ciphertext )) != 0 )
115115 goto out ;
116116 /* generate and encrypt KEM key with client key */
117- crypto_kem_sntrup4591761_enc (ciphertext , kem_key , client_pub );
117+ crypto_kem_sntrup761_enc (ciphertext , kem_key , client_pub );
118118 /* generate ECDH key pair, store server pubkey after ciphertext */
119- server_pub = ciphertext + crypto_kem_sntrup4591761_CIPHERTEXTBYTES ;
119+ server_pub = ciphertext + crypto_kem_sntrup761_CIPHERTEXTBYTES ;
120120 kexc25519_keygen (server_key , server_pub );
121121 /* append ECDH shared key */
122- client_pub += crypto_kem_sntrup4591761_PUBLICKEYBYTES ;
122+ client_pub += crypto_kem_sntrup761_PUBLICKEYBYTES ;
123123 if ((r = kexc25519_shared_key_ext (server_key , client_pub , buf , 1 )) < 0 )
124124 goto out ;
125125 if ((r = ssh_digest_buffer (kex -> hash_alg , buf , hash , sizeof (hash ))) != 0 )
126126 goto out ;
127127#ifdef DEBUG_KEXECDH
128128 dump_digest ("server public key 25519:" , server_pub , CURVE25519_SIZE );
129129 dump_digest ("server cipher text:" , ciphertext ,
130- crypto_kem_sntrup4591761_CIPHERTEXTBYTES );
130+ crypto_kem_sntrup761_CIPHERTEXTBYTES );
131131 dump_digest ("server kem key:" , kem_key , sizeof (kem_key ));
132132 dump_digest ("concatenation of KEM key and ECDH shared key:" ,
133133 sshbuf_ptr (buf ), sshbuf_len (buf ));
@@ -153,7 +153,7 @@ kex_kem_sntrup4591761x25519_enc(struct kex *kex,
153153}
154154
155155int
156- kex_kem_sntrup4591761x25519_dec (struct kex * kex ,
156+ kex_kem_sntrup761x25519_dec (struct kex * kex ,
157157 const struct sshbuf * server_blob , struct sshbuf * * shared_secretp )
158158{
159159 struct sshbuf * buf = NULL ;
@@ -165,35 +165,35 @@ kex_kem_sntrup4591761x25519_dec(struct kex *kex,
165165
166166 * shared_secretp = NULL ;
167167
168- need = crypto_kem_sntrup4591761_CIPHERTEXTBYTES + CURVE25519_SIZE ;
168+ need = crypto_kem_sntrup761_CIPHERTEXTBYTES + CURVE25519_SIZE ;
169169 if (sshbuf_len (server_blob ) != need ) {
170170 r = SSH_ERR_SIGNATURE_INVALID ;
171171 goto out ;
172172 }
173173 ciphertext = sshbuf_ptr (server_blob );
174- server_pub = ciphertext + crypto_kem_sntrup4591761_CIPHERTEXTBYTES ;
174+ server_pub = ciphertext + crypto_kem_sntrup761_CIPHERTEXTBYTES ;
175175#ifdef DEBUG_KEXECDH
176176 dump_digest ("server cipher text:" , ciphertext ,
177- crypto_kem_sntrup4591761_CIPHERTEXTBYTES );
177+ crypto_kem_sntrup761_CIPHERTEXTBYTES );
178178 dump_digest ("server public key c25519:" , server_pub , CURVE25519_SIZE );
179179#endif
180180 /* hash concatenation of KEM key and ECDH shared key */
181181 if ((buf = sshbuf_new ()) == NULL ) {
182182 r = SSH_ERR_ALLOC_FAIL ;
183183 goto out ;
184184 }
185- if ((r = sshbuf_reserve (buf , crypto_kem_sntrup4591761_BYTES ,
185+ if ((r = sshbuf_reserve (buf , crypto_kem_sntrup761_BYTES ,
186186 & kem_key )) != 0 )
187187 goto out ;
188- decoded = crypto_kem_sntrup4591761_dec (kem_key , ciphertext ,
189- kex -> sntrup4591761_client_key );
188+ decoded = crypto_kem_sntrup761_dec (kem_key , ciphertext ,
189+ kex -> sntrup761_client_key );
190190 if ((r = kexc25519_shared_key_ext (kex -> c25519_client_key , server_pub ,
191191 buf , 1 )) < 0 )
192192 goto out ;
193193 if ((r = ssh_digest_buffer (kex -> hash_alg , buf , hash , sizeof (hash ))) != 0 )
194194 goto out ;
195195#ifdef DEBUG_KEXECDH
196- dump_digest ("client kem key:" , kem_key , crypto_kem_sntrup4591761_BYTES );
196+ dump_digest ("client kem key:" , kem_key , crypto_kem_sntrup761_BYTES );
197197 dump_digest ("concatenation of KEM key and ECDH shared key:" ,
198198 sshbuf_ptr (buf ), sshbuf_len (buf ));
199199#endif
0 commit comments