Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
3750ffaa
Commit
3750ffaa
authored
Aug 30, 2016
by
Rusty Russell
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/pr/48'
parents
3e1be50f
61aead95
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
39 deletions
+25
-39
ccan/crypto/sha256/_info
ccan/crypto/sha256/_info
+5
-0
ccan/crypto/sha256/test/run-test-vectors.c
ccan/crypto/sha256/test/run-test-vectors.c
+20
-39
No files found.
ccan/crypto/sha256/_info
View file @
3750ffaa
...
...
@@ -45,6 +45,11 @@ int main(int argc, char *argv[])
return 0;
}
if (strcmp(argv[1], "testdepends") == 0) {
printf("ccan/str/hex\n");
return 0;
}
if (strcmp(argv[1], "libs") == 0) {
#ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL
printf("crypto\n");
...
...
ccan/crypto/sha256/test/run-test-vectors.c
View file @
3750ffaa
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/str/hex/hex.h>
/* Include the C files directly. */
#include <ccan/crypto/sha256/sha256.c>
#include <ccan/tap/tap.h>
...
...
@@ -7,53 +8,34 @@
struct
test
{
const
char
*
test
;
size_t
repetitions
;
beint32_t
result
[
8
]
;
const
char
*
result
;
};
static
struct
test
tests
[]
=
{
{
""
,
1
,
{
CPU_TO_BE32
(
0xe3b0c442
),
CPU_TO_BE32
(
0x98fc1c14
),
CPU_TO_BE32
(
0x9afbf4c8
),
CPU_TO_BE32
(
0x996fb924
),
CPU_TO_BE32
(
0x27ae41e4
),
CPU_TO_BE32
(
0x649b934c
),
CPU_TO_BE32
(
0xa495991b
),
CPU_TO_BE32
(
0x7852b855
)
}
},
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
{
"abc"
,
1
,
{
CPU_TO_BE32
(
0xba7816bf
),
CPU_TO_BE32
(
0x8f01cfea
),
CPU_TO_BE32
(
0x414140de
),
CPU_TO_BE32
(
0x5dae2223
),
CPU_TO_BE32
(
0xb00361a3
),
CPU_TO_BE32
(
0x96177a9c
),
CPU_TO_BE32
(
0xb410ff61
),
CPU_TO_BE32
(
0xf20015ad
)
}
},
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
,
1
,
{
CPU_TO_BE32
(
0x248d6a61
),
CPU_TO_BE32
(
0xd20638b8
),
CPU_TO_BE32
(
0xe5c02693
),
CPU_TO_BE32
(
0x0c3e6039
),
CPU_TO_BE32
(
0xa33ce459
),
CPU_TO_BE32
(
0x64ff2167
),
CPU_TO_BE32
(
0xf6ecedd4
),
CPU_TO_BE32
(
0x19db06c1
)
}
},
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
},
{
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
,
1
,
{
CPU_TO_BE32
(
0xcf5b16a7
),
CPU_TO_BE32
(
0x78af8380
),
CPU_TO_BE32
(
0x036ce59e
),
CPU_TO_BE32
(
0x7b049237
),
CPU_TO_BE32
(
0x0b249b11
),
CPU_TO_BE32
(
0xe8f07a51
),
CPU_TO_BE32
(
0xafac4503
),
CPU_TO_BE32
(
0x7afee9d1
)
}
},
"cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1"
},
{
"a"
,
1000000
,
{
CPU_TO_BE32
(
0xcdc76e5c
),
CPU_TO_BE32
(
0x9914fb92
),
CPU_TO_BE32
(
0x81a1c7e2
),
CPU_TO_BE32
(
0x84d73e67
),
CPU_TO_BE32
(
0xf1809a48
),
CPU_TO_BE32
(
0xa497200e
),
CPU_TO_BE32
(
0x046d39cc
),
CPU_TO_BE32
(
0xc7112cd0
)
}
}
"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0"
}
#if 0 /* Good test, but takes ages! */
, { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno", 16777216,
{ CPU_TO_BE32(0x50e72a0e), CPU_TO_BE32(0x26442fe2),
CPU_TO_BE32(0x552dc393), CPU_TO_BE32(0x8ac58658),
CPU_TO_BE32(0x228c0cbf), CPU_TO_BE32(0xb1d2ca87),
CPU_TO_BE32(0x2ae43526), CPU_TO_BE32(0x6fcd055e) } }
, { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno",
16777216,
"50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e" },
#endif
};
static
bool
do_test
(
const
struct
test
*
t
,
bool
single
)
static
bool
do_test
(
const
struct
test
*
t
)
{
struct
sha256
h
;
struct
sha256
h
,
expected
;
if
(
single
)
{
if
(
t
->
repetitions
!=
1
)
return
true
;
if
(
t
->
repetitions
==
1
)
sha256
(
&
h
,
t
->
test
,
strlen
(
t
->
test
));
}
else
{
else
{
struct
sha256_ctx
ctx
=
SHA256_INIT
;
size_t
i
;
...
...
@@ -62,21 +44,20 @@ static bool do_test(const struct test *t, bool single)
sha256_done
(
&
ctx
,
&
h
);
}
return
memcmp
(
&
h
.
u
,
t
->
result
,
sizeof
(
t
->
result
))
==
0
;
hex_decode
(
t
->
result
,
strlen
(
t
->
result
),
&
expected
,
sizeof
(
expected
));
return
memcmp
(
&
h
,
&
expected
,
sizeof
(
h
))
==
0
;
}
int
main
(
void
)
{
const
size_t
num_tests
=
sizeof
(
tests
)
/
sizeof
(
tests
[
0
]);
size_t
i
;
/* This is how many tests you plan to run */
plan_tests
(
sizeof
(
tests
)
/
sizeof
(
struct
test
)
*
2
);
plan_tests
(
num_tests
);
for
(
i
=
0
;
i
<
sizeof
(
tests
)
/
sizeof
(
struct
test
);
i
++
)
ok1
(
do_test
(
&
tests
[
i
],
false
));
for
(
i
=
0
;
i
<
sizeof
(
tests
)
/
sizeof
(
struct
test
);
i
++
)
ok1
(
do_test
(
&
tests
[
i
],
true
));
for
(
i
=
0
;
i
<
num_tests
;
i
++
)
ok1
(
do_test
(
&
tests
[
i
]));
/* This exits depending on whether all tests passed */
return
exit_status
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment