File: sshcrypto_kex_curve25519.c

package info (click to toggle)
tinyssh 20250501-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,388 kB
  • sloc: ansic: 20,245; sh: 1,582; python: 1,449; makefile: 913
file content (30 lines) | stat: -rw-r--r-- 718 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
20241114
Jan Mojzis
Public domain.
*/

#include "buf.h"
#include "crypto.h"
#include "purge.h"
#include "crypto_int16.h"
#include "sshcrypto.h"

int curve25519_enc(unsigned char *c, unsigned char *k,
                   const unsigned char *pk) {

    unsigned char onetimesk[crypto_dh_x25519_SECRETKEYBYTES];
    long long i;
    unsigned int d = 0;

    crypto_dh_x25519_keypair(/*onetimepk*/ c, onetimesk);
    crypto_dh_x25519(k, pk, onetimesk);
    purge(onetimesk, sizeof onetimesk);

    for (i = 0; i < crypto_dh_x25519_BYTES; ++i) d |= k[i];
    return crypto_int16_zero_mask(d);
}

void curve25519_putkemkey(struct buf *b, const unsigned char *x) {
    buf_putsharedsecret(b, x, crypto_dh_x25519_BYTES);
}