summaryrefslogtreecommitdiff
path: root/ecp/src/crypto/crypto.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-02-02 06:21:09 +0100
committerUros Majstorovic <majstor@majstor.org>2022-02-02 06:21:09 +0100
commitcd846d601227db0047c35b551858d62d6b794127 (patch)
tree1107f66259c455dc74df44752fd6b1f8c0470e6c /ecp/src/crypto/crypto.c
parentc5d4f45893cd3a70c2387f13fcf5ac97550bbfa0 (diff)
fixed new crypto
Diffstat (limited to 'ecp/src/crypto/crypto.c')
-rw-r--r--ecp/src/crypto/crypto.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/ecp/src/crypto/crypto.c b/ecp/src/crypto/crypto.c
index ae0b3d3..e1d06b3 100644
--- a/ecp/src/crypto/crypto.c
+++ b/ecp/src/crypto/crypto.c
@@ -1,16 +1,17 @@
#include <core.h>
#include <cr.h>
-#include <curve25519.h>
+#include <openssl/curve25519.h>
int ecp_cr_dh_mkpair(ecp_dh_public_t *pub, ecp_dh_private_t *priv, ecp_rng_t rand_buf) {
- int rv = X25519_keypair(*pub, *priv, rand_buf);
- if (!rv) return ECP_ERR;
+ X25519_keypair(*pub, *priv);
return ECP_OK;
}
int ecp_cr_dh_shsec(ecp_aead_key_t *shared, ecp_dh_public_t *pub, ecp_dh_private_t *priv) {
- int rv = X25519(*shared, *priv, *pub);
+ int rv;
+
+ rv = X25519(*shared, *priv, *pub);
if (!rv) return ECP_ERR;
return ECP_OK;
}
@@ -40,38 +41,53 @@ int ecp_cr_dh_pub_hash_eq(unsigned char *p1, unsigned char *p2) {
}
ssize_t ecp_cr_aead_enc(unsigned char *ct, size_t cl, unsigned char *pt, size_t pl, ecp_aead_key_t *k, unsigned char *n) {
+ uint8_t _n[ECP_AEAD_SIZE_NONCE + 4];
size_t ol;
- int rv = aead_chacha20_poly1305_seal(ct, &ol, cl, *k, ECP_AEAD_SIZE_TAG, n, ECP_AEAD_SIZE_NONCE, pt, pl, NULL, 0);
+ int rv;
+
+ memset(_n, 0, 4);
+ memcpy(_n + 4, n, ECP_AEAD_SIZE_NONCE);
+ rv = aead_chacha20_poly1305_seal(*k, ECP_AEAD_SIZE_TAG, ct, &ol, cl, _n, ECP_AEAD_SIZE_NONCE + 4, pt, pl, NULL, 0);
if (!rv) return ECP_ERR;
return ol;
}
ssize_t ecp_cr_aead_dec(unsigned char *pt, size_t pl, unsigned char *ct, size_t cl, ecp_aead_key_t *k, unsigned char *n) {
+ uint8_t _n[ECP_AEAD_SIZE_NONCE + 4];
size_t ol;
- int rv = aead_chacha20_poly1305_open(pt, &ol, pl, *k, ECP_AEAD_SIZE_TAG, n, ECP_AEAD_SIZE_NONCE, ct, cl, NULL, 0);
+ int rv;
+
+ memset(_n, 0, 4);
+ memcpy(_n + 4, n, ECP_AEAD_SIZE_NONCE);
+ rv = aead_chacha20_poly1305_open(*k, ECP_AEAD_SIZE_TAG, pt, &ol, pl, _n, ECP_AEAD_SIZE_NONCE + 4, ct, cl, NULL, 0);
if (!rv) return ECP_ERR;
return ol;
}
int ecp_cr_dsa_mkpair(ecp_dsa_public_t *pub, ecp_dsa_private_t *priv, ecp_rng_t rand_buf) {
- unsigned char key[2*ECP_DSA_SIZE_KEY];
+ unsigned char key[2*ECP_DSA_SIZE_KEY];
- int rv = ED25519_keypair(*pub, key, rand_buf);
- if (!rv) return ECP_ERR;
+ ED25519_keypair(*pub, key);
memcpy(priv, key, ECP_DSA_SIZE_KEY);
return ECP_OK;
}
int ecp_cr_dsa_sign(unsigned char *sig, unsigned char *m, size_t ml, ecp_dsa_public_t *p, ecp_dsa_private_t *s) {
unsigned char key[2*ECP_DSA_SIZE_KEY];
+ int rv;
+
memcpy(key, s, ECP_DSA_SIZE_KEY);
memcpy(key+ECP_DSA_SIZE_KEY, p, ECP_DSA_SIZE_KEY);
- int rv = ED25519_sign(sig, m, ml, key);
+ rv = ED25519_sign(sig, m, ml, key);
if (!rv) return ECP_ERR;
return ECP_OK;
}
int ecp_cr_dsa_verify(unsigned char *m, size_t ml, unsigned char *sig, ecp_dsa_public_t *p) {
- return ED25519_verify(m, ml, sig, *p);
+ int rv;
+
+ rv = ED25519_verify(m, ml, sig, *p);
+ if (rv == 1) return ECP_OK;
+ return ECP_ERR;
}