[BACK]Return to kexc25519.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/kexc25519.c between version 1.7 and 1.8

version 1.7, 2014/05/02 03:27:54 version 1.8, 2015/01/19 20:16:15
Line 33 
Line 33 
 #include <openssl/bn.h>  #include <openssl/bn.h>
 #include <openssl/evp.h>  #include <openssl/evp.h>
   
 #include "buffer.h"  #include "sshbuf.h"
 #include "ssh2.h"  #include "ssh2.h"
 #include "key.h"  #include "sshkey.h"
 #include "cipher.h"  #include "cipher.h"
 #include "kex.h"  #include "kex.h"
 #include "log.h"  #include "log.h"
 #include "digest.h"  #include "digest.h"
   #include "ssherr.h"
   
 extern int crypto_scalarmult_curve25519(u_char a[CURVE25519_SIZE],  extern int crypto_scalarmult_curve25519(u_char a[CURVE25519_SIZE],
     const u_char b[CURVE25519_SIZE], const u_char c[CURVE25519_SIZE])      const u_char b[CURVE25519_SIZE], const u_char c[CURVE25519_SIZE])
Line 56 
Line 57 
         crypto_scalarmult_curve25519(pub, key, basepoint);          crypto_scalarmult_curve25519(pub, key, basepoint);
 }  }
   
 void  int
 kexc25519_shared_key(const u_char key[CURVE25519_SIZE],  kexc25519_shared_key(const u_char key[CURVE25519_SIZE],
     const u_char pub[CURVE25519_SIZE], Buffer *out)      const u_char pub[CURVE25519_SIZE], struct sshbuf *out)
 {  {
         u_char shared_key[CURVE25519_SIZE];          u_char shared_key[CURVE25519_SIZE];
           int r;
   
         crypto_scalarmult_curve25519(shared_key, key, pub);          crypto_scalarmult_curve25519(shared_key, key, pub);
 #ifdef DEBUG_KEXECDH  #ifdef DEBUG_KEXECDH
         dump_digest("shared secret", shared_key, CURVE25519_SIZE);          dump_digest("shared secret", shared_key, CURVE25519_SIZE);
 #endif  #endif
         buffer_clear(out);          sshbuf_reset(out);
         buffer_put_bignum2_from_string(out, shared_key, CURVE25519_SIZE);          r = sshbuf_put_bignum2_bytes(out, shared_key, CURVE25519_SIZE);
         explicit_bzero(shared_key, CURVE25519_SIZE);          explicit_bzero(shared_key, CURVE25519_SIZE);
           return r;
 }  }
   
 void  int
 kex_c25519_hash(  kex_c25519_hash(
     int hash_alg,      int hash_alg,
     char *client_version_string,      const char *client_version_string,
     char *server_version_string,      const char *server_version_string,
     char *ckexinit, int ckexinitlen,      const char *ckexinit, size_t ckexinitlen,
     char *skexinit, int skexinitlen,      const char *skexinit, size_t skexinitlen,
     u_char *serverhostkeyblob, int sbloblen,      const u_char *serverhostkeyblob, size_t sbloblen,
     const u_char client_dh_pub[CURVE25519_SIZE],      const u_char client_dh_pub[CURVE25519_SIZE],
     const u_char server_dh_pub[CURVE25519_SIZE],      const u_char server_dh_pub[CURVE25519_SIZE],
     const u_char *shared_secret, u_int secretlen,      const u_char *shared_secret, size_t secretlen,
     u_char **hash, u_int *hashlen)      u_char *hash, size_t *hashlen)
 {  {
         Buffer b;          struct sshbuf *b;
         static u_char digest[SSH_DIGEST_MAX_LENGTH];          int r;
   
         buffer_init(&b);          if (*hashlen < ssh_digest_bytes(hash_alg))
         buffer_put_cstring(&b, client_version_string);                  return SSH_ERR_INVALID_ARGUMENT;
         buffer_put_cstring(&b, server_version_string);          if ((b = sshbuf_new()) == NULL)
                   return SSH_ERR_ALLOC_FAIL;
         /* kexinit messages: fake header: len+SSH2_MSG_KEXINIT */          if ((r = sshbuf_put_cstring(b, client_version_string)) < 0 ||
         buffer_put_int(&b, ckexinitlen+1);              (r = sshbuf_put_cstring(b, server_version_string)) < 0 ||
         buffer_put_char(&b, SSH2_MSG_KEXINIT);              /* kexinit messages: fake header: len+SSH2_MSG_KEXINIT */
         buffer_append(&b, ckexinit, ckexinitlen);              (r = sshbuf_put_u32(b, ckexinitlen+1)) < 0 ||
         buffer_put_int(&b, skexinitlen+1);              (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) < 0 ||
         buffer_put_char(&b, SSH2_MSG_KEXINIT);              (r = sshbuf_put(b, ckexinit, ckexinitlen)) < 0 ||
         buffer_append(&b, skexinit, skexinitlen);              (r = sshbuf_put_u32(b, skexinitlen+1)) < 0 ||
               (r = sshbuf_put_u8(b, SSH2_MSG_KEXINIT)) < 0 ||
         buffer_put_string(&b, serverhostkeyblob, sbloblen);              (r = sshbuf_put(b, skexinit, skexinitlen)) < 0 ||
         buffer_put_string(&b, client_dh_pub, CURVE25519_SIZE);              (r = sshbuf_put_string(b, serverhostkeyblob, sbloblen)) < 0 ||
         buffer_put_string(&b, server_dh_pub, CURVE25519_SIZE);              (r = sshbuf_put_string(b, client_dh_pub, CURVE25519_SIZE)) < 0 ||
         buffer_append(&b, shared_secret, secretlen);              (r = sshbuf_put_string(b, server_dh_pub, CURVE25519_SIZE)) < 0 ||
               (r = sshbuf_put(b, shared_secret, secretlen)) < 0) {
                   sshbuf_free(b);
                   return r;
           }
 #ifdef DEBUG_KEX  #ifdef DEBUG_KEX
         buffer_dump(&b);          sshbuf_dump(b, stderr);
 #endif  #endif
         if (ssh_digest_buffer(hash_alg, &b, digest, sizeof(digest)) != 0)          if (ssh_digest_buffer(hash_alg, b, hash, *hashlen) != 0) {
                 fatal("%s: digest_buffer failed", __func__);                  sshbuf_free(b);
                   return SSH_ERR_LIBCRYPTO_ERROR;
         buffer_free(&b);          }
           sshbuf_free(b);
           *hashlen = ssh_digest_bytes(hash_alg);
 #ifdef DEBUG_KEX  #ifdef DEBUG_KEX
         dump_digest("hash", digest, ssh_digest_bytes(hash_alg));          dump_digest("hash", hash, *hashlen);
 #endif  #endif
         *hash = digest;          return 0;
         *hashlen = ssh_digest_bytes(hash_alg);  
 }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8