Skip to content

Commit

Permalink
[libc][cgo] refs fibercrypto#105 Rewrite test cipher.bip32 to generat…
Browse files Browse the repository at this point in the history
…e error in armv7
  • Loading branch information
Maykel Arias Torres committed Sep 30, 2019
1 parent 0e97c27 commit 518495b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 40 deletions.
1 change: 1 addition & 0 deletions include/skytest.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int cutUxArray(coin__UxArray* slice, int start, int end, int elem_size, coin__Ux
int concatSlices(GoSlice_* slice1, GoSlice_* slice2, int elem_size, GoSlice_* result);
int concatUxArray(coin__UxArray* slice1, coin__UxArray* slice2, int elem_size, coin__UxArray* result);

int copyGoStringtoGoString_(GoString* pdest, GoString_* psource);
/*----------------------------------------------------------------------
* JSON helpers
*----------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions lib/cgo/cipher.hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func SKY_cipher_HashRipemd160(_data []byte, _arg1 *C.cipher__Ripemd160) (____err
//export SKY_cipher_SHA256_Set
func SKY_cipher_SHA256_Set(_g *C.cipher__SHA256, _b []byte) (____error_code uint32) {
g := (*cipher.SHA256)(unsafe.Pointer(_g))

if _b == nil {
____error_code = SKY_BAD_HANDLE
return
}
err := g.Set(_b)
____error_code = libErrorCode(err)
return
Expand All @@ -46,7 +49,7 @@ func SKY_cipher_SHA256_Set(_g *C.cipher__SHA256, _b []byte) (____error_code uint
func SKY_cipher_SHA256_Hex(_g *C.cipher__SHA256, _arg1 *C.GoString_) (____error_code uint32) {
g := (*cipher.SHA256)(unsafe.Pointer(_g))
__arg1 := g.Hex()
copyString(__arg1,_arg1)
copyString(__arg1, _arg1)
return
}

Expand Down
14 changes: 7 additions & 7 deletions lib/cgo/tests/check_cipher.bip32.bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,13 +1154,13 @@ Suite* cipher_bip32(void)

tc = tcase_create("cipher.bip32");
tcase_add_checked_fixture(tc, setup, teardown);
// tcase_add_test(tc, TestMaxChildDepthError);
// tcase_add_test(tc, TestParentPublicChildDerivation);
// // tcase_add_test(tc, TestBip32TestVectors);
// tcase_add_test(tc, TestDeserializePrivateInvalidStrings);
// tcase_add_test(tc, TestDeserializePublicInvalidStrings);
// tcase_add_test(tc, TestCantCreateHardenedPublicChild);
// tcase_add_test(tc, TestNewPrivateKeyFromPath);
tcase_add_test(tc, TestMaxChildDepthError);
tcase_add_test(tc, TestParentPublicChildDerivation);
tcase_add_test(tc, TestBip32TestVectors);
tcase_add_test(tc, TestDeserializePrivateInvalidStrings);
tcase_add_test(tc, TestDeserializePublicInvalidStrings);
tcase_add_test(tc, TestCantCreateHardenedPublicChild);
tcase_add_test(tc, TestNewPrivateKeyFromPath);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down
12 changes: 9 additions & 3 deletions lib/cgo/tests/check_cipher.hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ extern void freshSumSHA256(GoSlice bytes, cipher__SHA256* sha256);

START_TEST(TestSumSHA256)
{
printf("Load TestSumSHA256 \n");
GoUint8 bbuff[257];
GoUint8 cbuff[257];
GoSlice b = {bbuff, 0, 257};
GoSlice_ b_tmp = {bbuff, 0, 257};
cipher__SHA256 h1;
// randBytes(&b, 256);
SKY_cipher_RandByte(256, &b);
randBytes(&b, 256);
SKY_cipher_SumSHA256(b, &h1);
cipher__SHA256 tmp = "";
ck_assert_int_eq(isU8Eq(h1, tmp, 32), 0);
Expand All @@ -35,14 +36,16 @@ END_TEST

START_TEST(TestRipemd160Set)
{
printf("Load TestRipemd160Set \n");
cipher__Ripemd160 h;
unsigned char buff[101];
GoSlice slice = {buff, 0, 101};
GoSlice_ slice_tmp = {buff, 0, 101};
int error;

memset(h, 0, sizeof(cipher__Ripemd160));
randBytes(&slice, 21);

randBytes(&slice, 21);
error = SKY_cipher_Ripemd160_Set(&h, slice);
ck_assert(error == SKY_ErrInvalidLengthRipemd160);

Expand All @@ -67,6 +70,7 @@ END_TEST

START_TEST(TestDoubleSHA256)
{
printf("Load TestDoubleSHA256\n");
unsigned char bbuff[130];
GoSlice b = {bbuff, 0, 130};
randBytes(&b, 128);
Expand All @@ -81,6 +85,7 @@ END_TEST

START_TEST(TestXorSHA256)
{
printf("Load TestXorSHA256 \n");
unsigned char bbuff[129], cbuff[129];
GoSlice b = {bbuff, 0, 129};
GoSlice c = {cbuff, 0, 129};
Expand All @@ -106,6 +111,7 @@ END_TEST

START_TEST(TestMerkle)
{
printf("Load TestMerkle \n");
unsigned char buff[129];
cipher__SHA256 hashlist[5];
GoSlice b = {buff, 0, 129}, hashes = {hashlist, 0, 5};
Expand Down
36 changes: 8 additions & 28 deletions lib/cgo/tests/check_cipher.hash.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void freshSumSHA256(GoSlice bytes, cipher__SHA256* sha256)

START_TEST(TestAddSHA256)
{
printf("Load TestAddSHA256 \n");
unsigned char bbuff[130];
GoSlice b = {bbuff, 0, 130};
randBytes(&b, 128);
Expand All @@ -45,6 +46,7 @@ END_TEST

START_TEST(TestHashRipemd160)
{
printf("Load TestHashRipemd160\n");
cipher__Ripemd160 tmp;
cipher__Ripemd160 r;
cipher__Ripemd160 r2;
Expand All @@ -69,6 +71,7 @@ END_TEST

START_TEST(TestSHA256KnownValue)
{
printf("Load TestSHA256KnownValue\n");
typedef struct
{
char* input;
Expand Down Expand Up @@ -101,7 +104,7 @@ START_TEST(TestSHA256KnownValue)

SKY_cipher_SumSHA256(slice_input, &sha);

GoString tmp_output;
GoString_ tmp_output;

SKY_cipher_SHA256_Hex(&sha, &tmp_output);
registerMemCleanup((void*)tmp_output.p);
Expand All @@ -111,34 +114,10 @@ START_TEST(TestSHA256KnownValue)
}
END_TEST

START_TEST(TestSHA256Hex)
{
cipher__SHA256 h;
unsigned char buff[101];
GoSlice slice = {buff, 0, 101};
int error;

memset(&h, 0, sizeof(h));
randBytes(&slice, 32);
SKY_cipher_SHA256_Set(&h, slice);
GoString s;

SKY_cipher_SHA256_Hex(&h, &s);
registerMemCleanup((void*)s.p);

cipher__SHA256 h2;
error = SKY_cipher_SHA256FromHex(s, &h2);
ck_assert(error == SKY_OK);
ck_assert(isU8Eq(h, h2, 32));

GoString s2;
SKY_cipher_SHA256_Hex(&h2, &s2);
ck_assert(isGoStringEq(s, s2));
}
END_TEST

START_TEST(TestSHA256Set)
{
printf("Load TestSHA256Hex \n");
cipher__SHA256 h;
unsigned char buff[101];
GoSlice slice = {buff, 0, 101};
Expand Down Expand Up @@ -169,6 +148,7 @@ END_TEST

START_TEST(TestSHA256FromHex)
{
printf("Load TestSHA256FromHex \n");
unsigned int error;
cipher__SHA256 tmp;
// Invalid hex hash
Expand Down Expand Up @@ -200,6 +180,7 @@ END_TEST

START_TEST(TestSHA256Null)
{
printf("Load TestSHA256Null \n");
cipher__SHA256 x;
memset(&x, 0, sizeof(cipher__SHA256));
GoUint32 result;
Expand All @@ -221,12 +202,11 @@ Suite* common_check_cipher_hash(void)
Suite* s = suite_create("Load common check_cipher.hash");
TCase* tc;

tc = tcase_create("check_cipher.hash");
tc = tcase_create("check_cipher.hash.common");
tcase_add_test(tc, TestSHA256Set);
tcase_add_test(tc, TestAddSHA256);
tcase_add_test(tc, TestHashRipemd160);
tcase_add_test(tc, TestSHA256KnownValue);
tcase_add_test(tc, TestSHA256Hex);
tcase_add_test(tc, TestSHA256FromHex);
tcase_add_test(tc, TestSHA256Null);
suite_add_tcase(s, tc);
Expand Down
6 changes: 6 additions & 0 deletions lib/cgo/tests/testutils/libsky_testutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,9 @@ int concatUxArray(coin__UxArray* slice1, coin__UxArray* slice2, int elem_size, c
return SKY_OK;
}
}

int copyGoStringtoGoString_(GoString* pdest, GoString_* psource)
{
pdest->n = psource->p;
strncpy(pdest->p, psource->p, psource->n);
}

0 comments on commit 518495b

Please sign in to comment.