Skip to content
Permalink
Browse files

Implement real CID function

  • Loading branch information...
vladistan committed Jan 5, 2019
1 parent cf1c5c6 commit 2b4f08bd1c858c0df8d8da3d640f63e6e8af7dd4
Showing with 57 additions and 10 deletions.
  1. +22 −3 RunAllTests.cpp
  2. +35 −0 cid.c
  3. +0 −7 stubs.c
@@ -16,6 +16,7 @@ extern "C" {
}


const char *client_id = "b784c8325a15d7b7d62d4ded79b86b08fd0cbc8ed0099fee200b55ef8791eae6";


TEST_GROUP(Sizes) {
@@ -239,6 +240,9 @@ TEST(Encoders, EncByteValueTwoDigitsEdgeM1) {

TEST_GROUP(Crypto) {
void setup() {
const char *otp = "197548";
_BYTE src[4] = {10, 47, 114, 22};
set_loc_data(src, otp);
}

void teardown() {}
@@ -282,6 +286,20 @@ TEST(Crypto, BinEncKey) {

}

TEST(Crypto, Cid) {
unsigned int localip = 0x12345678;
_BYTE client_id_maybe[128];
char otp[9];
bzero(client_id_maybe, sizeof(client_id_maybe));
bzero(otp, sizeof(otp));

bool n = cid(&localip, client_id_maybe, otp);
LONGS_EQUAL(0x1, n)
STRCMP_EQUAL(otp, "197548");
MEMCMP_EQUAL(client_id_maybe, victim_id_b, 32);
}


TEST_GROUP(B32codecs) {
void setup() {}

@@ -309,11 +327,12 @@ TEST(B32codecs, properDec) {
LONGS_EQUAL(11, len);
STRCMP_EQUAL(exp, rv);
}

TEST_GROUP(PartialFunctions) {
void setup() {
// const char *otp = "197548";
// _BYTE src[4] = {10, 47, 114, 22};
// set_loc_data(src, otp);
const char *otp = "197548";
_BYTE src[4] = {10, 47, 114, 22};
set_loc_data(src, otp);

}

35 cid.c
@@ -54,3 +54,38 @@ int c_hh(void *data, size_t data_len, void *sign, size_t sign_len) {

return 1;
}

_BYTE locAddr[4];
_BYTE locOtp[20];

void set_loc_data(_BYTE* addr, const char* otp) {
memcpy(locAddr, addr, 4);
memcpy(locOtp, otp, 6);
locOtp[6] = 0;
}

bool cid(unsigned int *local_addr, _BYTE *client_id, char *r_otp) {


const char *bKey;
unsigned int bKey_len; // ST1C_4
const EVP_MD *evp_md; // rax

_BYTE localid[20];
_BYTE sign[80];
size_t sign_len;

memcpy(localid + 0, locAddr, 4);
memcpy(localid + 4, locOtp, 6);
strcpy(r_otp, locOtp);

bKey = getBinEncKey(&bKey_len);

evp_md = initEvpDigest();
HMAC(evp_md, bKey, bKey_len, localid, 10, sign, &sign_len);

memcpy(client_id, sign, 32);

return 1;
}

@@ -16,13 +16,6 @@ bool v_hh(void *string, long long int i, void *buffer, long long int i1) {
return 1;
}

bool cid(unsigned int *local_addr, _BYTE *client_id, char *otp_str) {

memcpy(client_id, victim_id_b, 32);
memcpy(otp_str, otp, 6);

return 1;
}

void encByte(_BYTE bEnc, _BYTE *dst) {
encHexDigit((bEnc & 0xf0) >> 4, dst);

0 comments on commit 2b4f08b

Please sign in to comment.
You can’t perform that action at this time.