mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-22 08:27:31 +09:00
re-introduce old nss im too tired for this
This commit is contained in:
parent
3c46be320d
commit
3a838106b9
2871 changed files with 1374431 additions and 1762417 deletions
|
|
@ -2,85 +2,19 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
/* nss headers */
|
||||
#include "prtypes.h"
|
||||
#include "plgetopt.h"
|
||||
#include "hasht.h"
|
||||
#include "nsslowhash.h"
|
||||
#include "secport.h"
|
||||
#include "hasht.h"
|
||||
#include "basicutil.h"
|
||||
|
||||
static char *progName = NULL;
|
||||
|
||||
/* can't call NSPR or NSSUtil directly, so just include
|
||||
* our own versions of SECU_ functions in basicutil.c.
|
||||
* We need this test program to link without those functions
|
||||
* so we can test that everyting works in a freebl only
|
||||
* environment */
|
||||
const char *hex = "0123456789abcdef";
|
||||
|
||||
const char printable[257] = {
|
||||
"................" /* 0x */
|
||||
"................" /* 1x */
|
||||
" !\"#$%&'()*+,-./" /* 2x */
|
||||
"0123456789:;<=>?" /* 3x */
|
||||
"@ABCDEFGHIJKLMNO" /* 4x */
|
||||
"PQRSTUVWXYZ[\\]^_" /* 5x */
|
||||
"`abcdefghijklmno" /* 6x */
|
||||
"pqrstuvwxyz{|}~." /* 7x */
|
||||
"................" /* 8x */
|
||||
"................" /* 9x */
|
||||
"................" /* ax */
|
||||
"................" /* bx */
|
||||
"................" /* cx */
|
||||
"................" /* dx */
|
||||
"................" /* ex */
|
||||
"................" /* fx */
|
||||
};
|
||||
|
||||
static void
|
||||
SECU_PrintBuf(FILE *out, const char *msg, const void *vp, int len)
|
||||
{
|
||||
const unsigned char *cp = (const unsigned char *)vp;
|
||||
char buf[80];
|
||||
char *bp;
|
||||
char *ap;
|
||||
|
||||
fprintf(out, "%s [Len: %d]\n", msg, len);
|
||||
memset(buf, ' ', sizeof buf);
|
||||
bp = buf;
|
||||
ap = buf + 50;
|
||||
while (--len >= 0) {
|
||||
unsigned char ch = *cp++;
|
||||
*bp++ = hex[(ch >> 4) & 0xf];
|
||||
*bp++ = hex[ch & 0xf];
|
||||
*bp++ = ' ';
|
||||
*ap++ = printable[ch];
|
||||
if (ap - buf >= 66) {
|
||||
*ap = 0;
|
||||
fprintf(out, " %s\n", buf);
|
||||
memset(buf, ' ', sizeof buf);
|
||||
bp = buf;
|
||||
ap = buf + 50;
|
||||
}
|
||||
}
|
||||
if (bp > buf) {
|
||||
*ap = 0;
|
||||
fprintf(out, " %s\n", buf);
|
||||
}
|
||||
}
|
||||
|
||||
/* simple version o print error */
|
||||
static void
|
||||
SECU_PrintError(const char *prog, const char *string)
|
||||
{
|
||||
fprintf(stderr, "%s: %s", prog, string);
|
||||
}
|
||||
|
||||
/* simple version o print error */
|
||||
static void
|
||||
SECU_PrintError3(const char *prog, const char *string, const char *string2)
|
||||
{
|
||||
fprintf(stderr, "%s: %s %s\n", prog, string, string2);
|
||||
}
|
||||
|
||||
static int
|
||||
test_long_message(NSSLOWInitContext *initCtx,
|
||||
HASH_HashType algoType, unsigned int hashLen,
|
||||
|
|
@ -94,7 +28,7 @@ test_long_message(NSSLOWInitContext *initCtx,
|
|||
* buffer and call update 1,000 times.
|
||||
*/
|
||||
unsigned char buf[1000];
|
||||
(void)memset(buf, 'a', sizeof(buf));
|
||||
(void)PORT_Memset(buf, 'a', sizeof(buf));
|
||||
|
||||
ctx = NSSLOWHASH_NewContext(initCtx, algoType);
|
||||
if (ctx == NULL) {
|
||||
|
|
@ -108,8 +42,8 @@ test_long_message(NSSLOWInitContext *initCtx,
|
|||
}
|
||||
|
||||
NSSLOWHASH_End(ctx, results, &len, hashLen);
|
||||
assert(len == hashLen);
|
||||
assert(PORT_Memcmp(expected, results, hashLen) == 0);
|
||||
PR_ASSERT(len == hashLen);
|
||||
PR_ASSERT(PORT_Memcmp(expected, results, hashLen) == 0);
|
||||
if (PORT_Memcmp(expected, results, len) != 0) {
|
||||
SECU_PrintError(progName, "Hash mismatch\n");
|
||||
SECU_PrintBuf(stdout, "Expected: ", expected, hashLen);
|
||||
|
|
@ -130,9 +64,11 @@ test_long_message_sha1(NSSLOWInitContext *initCtx)
|
|||
/* Test vector from FIPS 180-2: appendix B.3. */
|
||||
|
||||
/* 34aa973c d4c4daa4 f61eeb2b dbad2731 6534016f. */
|
||||
static const PRUint8 expected[SHA256_LENGTH] = { 0x34, 0xaa, 0x97, 0x3c, 0xd4, 0xc4, 0xda, 0xa4, 0xf6, 0x1e, 0xeb, 0x2b,
|
||||
0xdb, 0xad, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6f };
|
||||
|
||||
static const PRUint8 expected[SHA256_LENGTH] =
|
||||
{ 0x34, 0xaa, 0x97, 0x3c, 0xd4, 0xc4, 0xda, 0xa4, 0xf6, 0x1e, 0xeb, 0x2b,
|
||||
0xdb, 0xad, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6f };
|
||||
unsigned char buf[1000];
|
||||
(void)PORT_Memset(buf, 'a', sizeof(buf));
|
||||
return test_long_message(initCtx, HASH_AlgSHA1,
|
||||
SHA1_LENGTH, &expected[0], results);
|
||||
}
|
||||
|
|
@ -142,9 +78,11 @@ test_long_message_sha256(NSSLOWInitContext *initCtx)
|
|||
{
|
||||
PRUint8 results[SHA256_LENGTH];
|
||||
/* cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0. */
|
||||
static const PRUint8 expected[SHA256_LENGTH] = { 0xcd, 0xc7, 0x6e, 0x5c, 0x99, 0x14, 0xfb, 0x92, 0x81, 0xa1, 0xc7, 0xe2, 0x84, 0xd7, 0x3e, 0x67,
|
||||
0xf1, 0x80, 0x9a, 0x48, 0xa4, 0x97, 0x20, 0x0e, 0x04, 0x6d, 0x39, 0xcc, 0xc7, 0x11, 0x2c, 0xd0 };
|
||||
|
||||
static const PRUint8 expected[SHA256_LENGTH] =
|
||||
{ 0xcd, 0xc7, 0x6e, 0x5c, 0x99, 0x14, 0xfb, 0x92, 0x81, 0xa1, 0xc7, 0xe2, 0x84, 0xd7, 0x3e, 0x67,
|
||||
0xf1, 0x80, 0x9a, 0x48, 0xa4, 0x97, 0x20, 0x0e, 0x04, 0x6d, 0x39, 0xcc, 0xc7, 0x11, 0x2c, 0xd0 };
|
||||
unsigned char buf[1000];
|
||||
(void)PORT_Memset(buf, 'a', sizeof(buf));
|
||||
return test_long_message(initCtx, HASH_AlgSHA256,
|
||||
SHA256_LENGTH, &expected[0], results);
|
||||
}
|
||||
|
|
@ -162,12 +100,15 @@ test_long_message_sha384(NSSLOWInitContext *initCtx)
|
|||
07b8b3dc38ecc4eb
|
||||
ae97ddd87f3d8985.
|
||||
*/
|
||||
static const PRUint8 expected[SHA384_LENGTH] = { 0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
|
||||
0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
|
||||
0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
|
||||
0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
|
||||
0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
|
||||
0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85 };
|
||||
static const PRUint8 expected[SHA384_LENGTH] =
|
||||
{ 0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
|
||||
0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
|
||||
0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
|
||||
0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
|
||||
0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
|
||||
0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85 };
|
||||
unsigned char buf[1000];
|
||||
(void)PORT_Memset(buf, 'a', sizeof(buf));
|
||||
|
||||
return test_long_message(initCtx, HASH_AlgSHA384,
|
||||
SHA384_LENGTH, &expected[0], results);
|
||||
|
|
@ -178,10 +119,13 @@ test_long_message_sha512(NSSLOWInitContext *initCtx)
|
|||
{
|
||||
PRUint8 results[SHA512_LENGTH];
|
||||
/* Test vector from FIPS 180-2: appendix B.3. */
|
||||
static const PRUint8 expected[SHA512_LENGTH] = { 0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64, 0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
|
||||
0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28, 0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
|
||||
0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a, 0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
|
||||
0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e, 0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b };
|
||||
static const PRUint8 expected[SHA512_LENGTH] =
|
||||
{ 0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64, 0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
|
||||
0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28, 0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
|
||||
0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a, 0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
|
||||
0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e, 0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b };
|
||||
unsigned char buf[1000];
|
||||
(void)PORT_Memset(buf, 'a', sizeof(buf));
|
||||
|
||||
return test_long_message(initCtx, HASH_AlgSHA512,
|
||||
SHA512_LENGTH, &expected[0], results);
|
||||
|
|
@ -206,8 +150,8 @@ testMessageDigest(NSSLOWInitContext *initCtx,
|
|||
NSSLOWHASH_Begin(ctx);
|
||||
NSSLOWHASH_Update(ctx, message, PORT_Strlen((const char *)message));
|
||||
NSSLOWHASH_End(ctx, results, &len, hashLen);
|
||||
assert(len == hashLen);
|
||||
assert(PORT_Memcmp(expected, results, len) == 0);
|
||||
PR_ASSERT(len == hashLen);
|
||||
PR_ASSERT(PORT_Memcmp(expected, results, len) == 0);
|
||||
|
||||
if (PORT_Memcmp(expected, results, len) != 0) {
|
||||
SECU_PrintError(progName, "Hash mismatch\n");
|
||||
|
|
@ -471,7 +415,7 @@ main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (argc < 2 || !argv[1] || strlen(argv[1]) == 0) {
|
||||
if (argc || !argv[1] || strlen(argv[1]) == 0) {
|
||||
rv += testMD5(initCtx);
|
||||
rv += testSHA1(initCtx);
|
||||
rv += testSHA224(initCtx);
|
||||
|
|
@ -484,14 +428,14 @@ main(int argc, char **argv)
|
|||
rv += testSHA1(initCtx);
|
||||
} else if (strcmp(argv[1], "SHA224") == 0) {
|
||||
rv += testSHA224(initCtx);
|
||||
} else if (strcmp(argv[1], "SHA256") == 0) {
|
||||
} else if (strcmp(argv[1], "SHA226") == 0) {
|
||||
rv += testSHA256(initCtx);
|
||||
} else if (strcmp(argv[1], "SHA384") == 0) {
|
||||
rv += testSHA384(initCtx);
|
||||
} else if (strcmp(argv[1], "SHA512") == 0) {
|
||||
rv += testSHA512(initCtx);
|
||||
} else {
|
||||
SECU_PrintError3(progName, "Unsupported hash type", argv[0]);
|
||||
SECU_PrintError(progName, "Unsupported hash type %s\n", argv[0]);
|
||||
Usage();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue