port crypto buildable with our code base

This commit is contained in:
hathach committed 2018-01-09 17:24:25 +07:00
1 parent a721478f1e
commit b152e84a2f
5 files changed
+36 -15

No files matched your search

@@ -119,6 +119,8 @@ err_t HAPCharacteristic::begin(void)
_format_desc.format = temp_format;
_usr_descriptor = temp_usr;
LOG_LV2("HAP", "Added Char UUID=0x%04X, CID=0x%04X", uuid._uuid.uuid, _cid);
return ERROR_NONE;
}
+5 -7
View File
@@ -13,7 +13,7 @@
//#include <pstorage.h>
//#include <app_scheduler.h>
#include <nrf_soc.h>
#include <Nffs.h>
#include "nffs/nffs.h"
#include "crypto.h"
@@ -86,12 +86,10 @@ static uint8_t crypto_loadKeys(void)
// err_code = pstorage_load((uint8_t*)&keys, &handle, sizeof(keys), 0);
// APP_ERROR_CHECK(err_code);
NffsFile file(CRYPTO_KEYFILE, FS_ACCESS_WRITE | FS_ACCESS_READ);
if ( !file.exists() ) return 0;
crypto_persistent_keys_t keys = {};
file.read(&keys, sizeof(keys));
uint32_t keylen = sizeof(keys);
fsutil_read_file(CRYPTO_KEYFILE, 0, keylen, &keys, &keylen);
if (keys.valid0 == 0x55 && keys.valid1 == 0xAA && keys.instance == CRYPTO_INSTANCE)
{
@@ -139,7 +137,7 @@ void crypto_storeKeys(void)
keys.valid0 = 0x55;
keys.valid1 = 0xAA;
Nffs.writeFile(CRYPTO_KEYFILE, &keys, sizeof(keys));
fsutil_write_file(CRYPTO_KEYFILE, &keys, sizeof(keys));
// err_code = pstorage_update(&handle, (uint8_t*)&keys, sizeof(keys), 0);
// APP_ERROR_CHECK(err_code);
+2
View File
@@ -7,8 +7,10 @@
//#include <softdevice_handler.h>
#include "nrf_soc.h"
#include "random.h"
#define APP_ERROR_CHECK(_err) if (_err != NRF_SUCCESS) return
void random_create(uint8_t* p_result, uint8_t length)
{
+13 -7
View File
@@ -24,6 +24,8 @@
#include "../tweetnacl-modified/tweetnacl.h"
//#include "homekit/pairing.h"
#include "common_inc.h"
#define E(V) (((V) << 24) | ((V) >> 24) | (((V) >> 8) & 0x0000FF00) | (((V) << 8) & 0x00FF0000))
static const uint32_t srp_N[] =
{
@@ -61,17 +63,21 @@ static const uint8_t srp_N_hash_srp_G_hash[] =
0x68, 0x3C, 0x9E, 0x78, 0x32, 0x96, 0xDD, 0x16, 0x93, 0xEB, 0xC7, 0x1C, 0xF5, 0xA5, 0x3D, 0xA3
};
#define HOMEKIT_CONFIG_PINCODE "112-23-344"
static const uint8_t pincode[21] = "Pair-Setup:" HOMEKIT_CONFIG_PINCODE;
srp_keys_t srp;
static void MPI_ERROR_CHECK(int CODE)
{
if (CODE != 0)
{
APP_ERROR_CHECK(NRF_ERROR_INTERNAL);
}
}
//static void MPI_ERROR_CHECK(int CODE)
//{
// if (CODE != 0)
// {
// APP_ERROR_CHECK(NRF_ERROR_INTERNAL);
// }
//}
#define MPI_ERROR_CHECK(_code) VERIFY_STATUS(_code, )
void srp_init(void)
@@ -181,7 +181,20 @@ static HAPResponse_t* pairing_setup_write_cb (HAPCharacteristic& chr, ble_gatts_
break;
case PAIRING_TYPE_STATE:
LOG_LV2("HAP", "State = M%d", *((uint8_t const*)ktlv.value));
{
uint8_t state = *((uint8_t const*)ktlv.value);
LOG_LV2("HAP", "State = M%d", state);
switch (state)
{
case 1: // M1
// if paired return PAIRING_ERROR_UNAVAILABLE
// tries more than 100 time return PAIRING_ERROR_MAX_TRIES
// pairing with other iOS return PAIRING_ERROR_BUSY
break;
}
}
break;
// ignore other type