Browse Source

Crypto fixes for openssl 1.1

Remove repeater code from dml_trx
master
Jeroen Vreeken 4 years ago
parent
commit
c88cdbff76
3 changed files with 21 additions and 17 deletions
  1. +16
    -9
      dml_crypto.c
  2. +4
    -8
      dml_trx.c
  3. +1
    -0
      htdocs/index.html

+ 16
- 9
dml_crypto.c View File

@ -20,7 +20,10 @@
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/ecdsa.h>
#include <string.h>
X509_STORE *x509_store;
@ -145,18 +148,18 @@ int dml_crypto_cert_add_verify(void *certdata, size_t size, uint8_t id[DML_ID_SI
EVP_PKEY *evp_key = X509_get_pubkey(cert);
if (!evp_key)
goto err_key;
if (EVP_PKEY_type(evp_key->type) != EVP_PKEY_EC)
goto err_key_type;
/* only 256 bits EC for now */
if (EVP_PKEY_bits(evp_key) != 256)
goto err_bits;
dk->ec_key = EVP_PKEY_get1_EC_KEY(evp_key);
if (!dk->ec_key)
goto err_key_type;
EVP_PKEY_free(evp_key);
return !(rc == 1);
err_bits:
err_key_type:
err_bits:
EVP_PKEY_free(evp_key);
err_key:
err_name:
@ -273,8 +276,10 @@ bool dml_crypto_verify(void *data, size_t len, uint8_t sig[DML_SIG_SIZE], struct
SHA256_Final(digest, &sha256);
ECDSA_SIG *ecsig = ECDSA_SIG_new();
BN_bin2bn(sig, 32, ecsig->r);
BN_bin2bn(sig + 32, 32, ecsig->s);
BIGNUM *r, *s;
r = BN_bin2bn(sig, 32, NULL);
s = BN_bin2bn(sig + 32, 32, NULL);
ECDSA_SIG_set0(ecsig, r, s);
int ret = ECDSA_do_verify(digest, SHA256_DIGEST_LENGTH, ecsig, dk->ec_key);
@ -300,10 +305,12 @@ int dml_crypto_sign(uint8_t sig[DML_SIG_SIZE], void *data, size_t len, struct dm
ECDSA_SIG *ecsig = ECDSA_do_sign(digest, SHA256_DIGEST_LENGTH, dk->ec_key);
memset(sig, 0, 64);
int r_off = 32 - BN_num_bytes(ecsig->r);
int s_off = 32 - BN_num_bytes(ecsig->s);
BN_bn2bin(ecsig->r, sig + r_off);
BN_bn2bin(ecsig->s, sig + 32 + s_off);
const BIGNUM *r, *s;
ECDSA_SIG_get0(ecsig, &r, &s);
int r_off = 32 - BN_num_bytes(r);
int s_off = 32 - BN_num_bytes(s);
BN_bn2bin(r, sig + r_off);
BN_bn2bin(s, sig + 32 + s_off);
ECDSA_SIG_free(ecsig);
return 0;


+ 4
- 8
dml_trx.c View File

@ -58,7 +58,7 @@
#define debug(...) printf(__VA_ARGS__)
static bool fullduplex = false;
static bool repeater = false;
static bool digipeater = false;
static bool allow_commands = true;
static struct dml_stream *stream_dv;
@ -586,7 +586,7 @@ static void recv_data(void *data, size_t size)
// printf("mode %d state %d\n", mode, state);
if (!rx_state || (fullduplex && !repeater)) {
if (!rx_state || fullduplex) {
if (state != tx_state) {
char call[ETH_AR_CALL_SIZE];
int ssid;
@ -675,10 +675,6 @@ static int dv_in_cb(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size
send_data(data, 8 + size, stream_dv);
if (repeater) {
trx_dv_send(from, mac_bcast, mode, dv, size);
}
fprs_update_mac(from);
dml_poll_timeout(&rx_state, rx_state ?
@ -882,7 +878,7 @@ static int fprs_cb(void *arg, uint8_t from[6], uint8_t *fprsdata, size_t size)
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
if (repeater) {
if (digipeater) {
/* Digipeat the incomming FPRS packet */
trx_dv_send_fprs(mac_dev, mac_bcast, f_data, f_size);
}
@ -995,7 +991,7 @@ int main(int argc, char **argv)
key = dml_config_value("key", NULL, "");
fullduplex = atoi(dml_config_value("fullduplex", NULL, "0"));
repeater = atoi(dml_config_value("repeater", NULL, "0"));
digipeater = atoi(dml_config_value("digipeater", NULL, "0"));
allow_commands = atoi(dml_config_value("allow_commands", NULL, "0"));
command_pipe_name = dml_config_value("command_pipe_name", NULL, NULL);


+ 1
- 0
htdocs/index.html View File

@ -572,6 +572,7 @@ function dmlc2()
var dv = new DataView(c2_buf.buffer);
for (i = 0; i < nr; i++) {
samples[i] = dv.getInt16(c2_buf.byteOffset + i*2, true) / 32768.0;
// samples[i] = Int16Array(c2_buf)[i] / 32768.0;
}
} else if (newmode == 'be16') {
var i;


Loading…
Cancel
Save