Commit 1f2f0582 authored by Geoff Simmons's avatar Geoff Simmons

test the digest object with SHA3_256

parent 27048787
Pipeline #57 skipped
......@@ -10,33 +10,38 @@ varnish v1 -vcl {
backend b { .host = "${bad_ip}"; }
sub vcl_init {
# http://wolfgang-ehrhardt.de/hmac-sha3-testvectors.html
new k1 = blobcode.blob(HEX,
"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
new ehrhardt1 = blobdigest.hmac(SHA3_256, k1.get());
new k2 = blobcode.blob(IDENTITY, "Jefe");
new ehrhardt2 = blobdigest.hmac(SHA3_256, k2.get());
new k3 = blobcode.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new ehrhardt3 = blobdigest.hmac(SHA3_256, k3.get());
new k4 = blobcode.blob(HEX,
"0102030405060708090a0b0c0d0e0f10111213141516171819");
new ehrhardt4 = blobdigest.hmac(SHA3_256, k4.get());
new k5 = blobcode.blob(HEX,
"0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c");
new ehrhardt5 = blobdigest.hmac(SHA3_256, k5.get());
new k6 = blobcode.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new ehrhardt6 = blobdigest.hmac(SHA3_256, k6.get());
new k7 = blobcode.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new ehrhardt7 = blobdigest.hmac(SHA3_256, k7.get());
new a = blobcode.blob(IDENTITY, "a");
new msg = blobcode.blob(IDENTITY, "message");
new alphalc = blobcode.blob(IDENTITY,
"abcdefghijklmnopqrstuvwxyz");
new empty = blobcode.blob(IDENTITY, "");
new alphauc = blobcode.blob(IDENTITY,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
new digits = blobcode.blob(IDENTITY, "1234567890");
new pangram =
blobcode.blob(IDENTITY,
"The quick brown fox jumps over the lazy dog");
# Byte values 0 to 63, 64 to 127, etc up to 255
new b0to63 = blobcode.blob(BASE64,
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+Pw==");
new b64to127 = blobcode.blob(BASE64,
"QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+fw==");
new b128to191 = blobcode.blob(BASE64,
"gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+vw==");
new b192to255 = blobcode.blob(BASE64,
"wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==");
new d1 = blobdigest.digest(SHA3_256);
new d2 = blobdigest.digest(SHA3_256);
new d3 = blobdigest.digest(SHA3_256, a.get());
new d4 = blobdigest.digest(SHA3_256, msg.get());
new d5 = blobdigest.digest(SHA3_256, alphalc.get());
new d6 = blobdigest.digest(SHA3_256, empty.get());
new d7 = blobdigest.digest(SHA3_256, alphauc.get());
new d8 = blobdigest.digest(SHA3_256, digits.get());
new d9 = blobdigest.digest(SHA3_256, pangram.get());
new d11 = blobdigest.digest(SHA3_256, b0to63.get());
}
sub vcl_recv {
......@@ -44,54 +49,232 @@ varnish v1 -vcl {
}
sub vcl_synth {
set resp.http.empty
if (!d1.update(empty.get())) {
set resp.status = 500;
return(deliver);
}
set resp.http.empty = blobcode.encode(HEXUC, d1.final());
if (!d2.update(a.get())) {
set resp.status = 500;
return(deliver);
}
set resp.http.a = blobcode.encode(HEXUC, d2.final());
if (!d3.update(blobcode.decode(IDENTITY, "b"))) {
set resp.status = 500;
return(deliver);
}
if (!d3.update(blobcode.decode(IDENTITY, "c"))) {
set resp.status = 500;
return(deliver);
}
set resp.http.abc = blobcode.encode(HEXUC, d3.final());
if (!d4.update(blobcode.decode(IDENTITY, " "))) {
set resp.status = 500;
return(deliver);
}
if (!d4.update(blobcode.decode(IDENTITY, "digest"))) {
set resp.status = 500;
return(deliver);
}
set resp.http.msgdigest = blobcode.encode(HEXUC, d4.final());
if (!d5.update(blobcode.decode(IDENTITY, ""))) {
set resp.status = 500;
return(deliver);
}
set resp.http.alphalc = blobcode.encode(HEXUC, d5.final());
if (!d6.update(blobcode.decode(IDENTITY,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))) {
set resp.status = 500;
return(deliver);
}
set resp.http.alphasoup = blobcode.encode(HEXLC, d6.final());
if (!d7.update(alphalc.get())) {
set resp.status = 500;
return(deliver);
}
if (!d7.update(blobcode.decode(IDENTITY, "0123456789"))) {
set resp.status = 500;
return(deliver);
}
set resp.http.alphanum = blobcode.encode(HEXUC, d7.final());
if (!d8.update(digits.get())) {
set resp.status = 500;
return(deliver);
}
if (!d8.update(digits.get())) {
set resp.status = 500;
return(deliver);
}
if (!d8.update(digits.get())) {
set resp.status = 500;
return(deliver);
}
if (!d8.update(digits.get())) {
set resp.status = 500;
return(deliver);
}
if (!d8.update(digits.get())) {
set resp.status = 500;
return(deliver);
}
if (!d8.update(digits.get())) {
set resp.status = 500;
return(deliver);
}
if (!d8.update(digits.get())) {
set resp.status = 500;
return(deliver);
}
set resp.http.digits = blobcode.encode(HEXUC, d8.final());
set resp.http.pangram = blobcode.encode(HEXUC, d9.final());
if (!d11.update(b64to127.get())) {
set resp.status = 500;
return(deliver);
}
if (!d11.update(b128to191.get())) {
set resp.status = 500;
return(deliver);
}
if (!d11.update(b192to255.get())) {
set resp.status = 500;
return(deliver);
}
set resp.http.allbytes = blobcode.encode(HEXLC, d11.final());
# Tests for the hash() function
set resp.http.emptyf
= blobcode.encode(HEXUC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY, "")));
set resp.http.a
set resp.http.af
= blobcode.encode(HEXUC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY, "a")));
set resp.http.abc
set resp.http.abcf
= blobcode.encode(HEXUC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY, "abc")));
set resp.http.msgdigest
set resp.http.msgdigestf
= blobcode.encode(HEXUC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY,
"message digest")));
set resp.http.alphalc
set resp.http.alphalcf
= blobcode.encode(HEXUC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY,
"abcdefghijklmnopqrstuvwxyz")));
set resp.http.alphasoup
set resp.http.alphasoupf
= blobcode.encode(HEXLC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
set resp.http.alphanum
set resp.http.alphanumf
= blobcode.encode(HEXUC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")));
set resp.http.digits
set resp.http.digitsf
= blobcode.encode(HEXUC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY,
"12345678901234567890123456789012345678901234567890123456789012345678901234567890")));
set resp.http.pangram
set resp.http.pangramf
= blobcode.encode(HEXUC, blobdigest.hash(SHA3_256,
blobcode.decode(IDENTITY,
"The quick brown fox jumps over the lazy dog")));
# all 256 byte values in ascending, big-endian order
set resp.http.allbytes
# all 256 byte values in ascending order
set resp.http.allbytesf
= blobcode.encode(HEXLC, blobdigest.hash(SHA3_256,
blobcode.decode(BASE64,
"AQACAQMCBAMFBAYFBwYIBwkICgkLCgwLDQwODQ8OEA8REBIRExIUExUUFhUXFhgXGRgaGRsaHBsdHB4dHx4gHyEgIiEjIiQjJSQmJScmKCcpKCopKyosKy0sLi0vLjAvMTAyMTMyNDM1NDY1NzY4Nzk4Ojk7Ojw7PTw+PT8+QD9BQEJBQ0JEQ0VERkVHRkhHSUhKSUtKTEtNTE5NT05QT1FQUlFTUlRTVVRWVVdWWFdZWFpZW1pcW11cXl1fXmBfYWBiYWNiZGNlZGZlZ2ZoZ2loamlramxrbWxubW9ucG9xcHJxc3J0c3V0dnV3dnh3eXh6eXt6fHt9fH59f36Afw==")));
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==")));
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
# from librhash
expect resp.http.empty == "A7FFC6F8BF1ED76651C14756A061D662F580FF4DE43B49FA82D80A4B80F8434A"
expect resp.http.a == "80084BF2FBA02475726FEB2CAB2D8215EAB14BC6BDD8BFB2C8151257032ECD8B"
expect resp.http.abc == "3A985DA74FE225B2045C172D6BD390BD855F086E3E9D525B46BFE24511431532"
expect resp.http.msgdigest == "EDCDB2069366E75243860C18C3A11465ECA34BCE6143D30C8665CEFCFD32BFFD"
expect resp.http.alphalc == "7CAB2DC765E21B241DBC1C255CE620B29F527C6D5E7F5F843E56288F0D707521"
expect resp.http.alphanum == "A79D6A9DA47F04A3B9A9323EC9991F2105D4C78A7BC7BEEB103855A7A11DFB9F"
expect resp.http.digits == "293E5CE4CE54EE71990AB06E511B7CCD62722B1BEB414F5FF65C8274E0F5BE1D"
expect resp.http.pangram == "69070DDA01975C8C120C3AADA1B282394E7F032FA9CF32F4CB2259A0897DFC04"
# from http://www.di-mgt.com.au/sha_testvectors.html
expect resp.http.alphasoup == "41c0dba2a9d6240849100376a8235e2c82e1b9998a999e21db32dd97496d3376"
# verified with: base64 -d | rhash --sha3-256 -
expect resp.http.allbytes == "9b04c091da96b997afb8f2585d608aebe9c4a904f7d52c8f28c7e4d2dd9fba5f"
# hash() function
expect resp.http.emptyf == "A7FFC6F8BF1ED76651C14756A061D662F580FF4DE43B49FA82D80A4B80F8434A"
expect resp.http.af == "80084BF2FBA02475726FEB2CAB2D8215EAB14BC6BDD8BFB2C8151257032ECD8B"
expect resp.http.abcf == "3A985DA74FE225B2045C172D6BD390BD855F086E3E9D525B46BFE24511431532"
expect resp.http.msgdigestf == "EDCDB2069366E75243860C18C3A11465ECA34BCE6143D30C8665CEFCFD32BFFD"
expect resp.http.alphalcf == "7CAB2DC765E21B241DBC1C255CE620B29F527C6D5E7F5F843E56288F0D707521"
expect resp.http.alphanumf == "A79D6A9DA47F04A3B9A9323EC9991F2105D4C78A7BC7BEEB103855A7A11DFB9F"
expect resp.http.digitsf == "293E5CE4CE54EE71990AB06E511B7CCD62722B1BEB414F5FF65C8274E0F5BE1D"
expect resp.http.pangramf == "69070DDA01975C8C120C3AADA1B282394E7F032FA9CF32F4CB2259A0897DFC04"
expect resp.http.alphasoupf == "41c0dba2a9d6240849100376a8235e2c82e1b9998a999e21db32dd97496d3376"
expect resp.http.allbytesf == "9b04c091da96b997afb8f2585d608aebe9c4a904f7d52c8f28c7e4d2dd9fba5f"
} -run
varnish v1 -vcl {
import blobdigest from "${vmod_topbuild}/src/.libs/libvmod_blobdigest.so";
import blobcode;
backend b { .host = "${bad_ip}"; }
sub vcl_init {
# http://wolfgang-ehrhardt.de/hmac-sha3-testvectors.html
new k1 = blobcode.blob(HEX,
"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
new ehrhardt1 = blobdigest.hmac(SHA3_256, k1.get());
new k2 = blobcode.blob(IDENTITY, "Jefe");
new ehrhardt2 = blobdigest.hmac(SHA3_256, k2.get());
new k3 = blobcode.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new ehrhardt3 = blobdigest.hmac(SHA3_256, k3.get());
new k4 = blobcode.blob(HEX,
"0102030405060708090a0b0c0d0e0f10111213141516171819");
new ehrhardt4 = blobdigest.hmac(SHA3_256, k4.get());
new k5 = blobcode.blob(HEX,
"0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c");
new ehrhardt5 = blobdigest.hmac(SHA3_256, k5.get());
new k6 = blobcode.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new ehrhardt6 = blobdigest.hmac(SHA3_256, k6.get());
new k7 = blobcode.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new ehrhardt7 = blobdigest.hmac(SHA3_256, k7.get());
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.ehrhardt1 = blobcode.encode(HEXLC,
ehrhardt1.hmac(blobcode.decode(IDENTITY, "Hi There")));
......@@ -135,30 +318,14 @@ varnish v1 -vcl {
ehrhardt7.hmac(blobcode.decode(IDENTITY,
"This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.")));
}
} -start
}
}
client c1 {
txreq
rxresp
expect resp.status == 200
# from librhash
expect resp.http.empty == "A7FFC6F8BF1ED76651C14756A061D662F580FF4DE43B49FA82D80A4B80F8434A"
expect resp.http.a == "80084BF2FBA02475726FEB2CAB2D8215EAB14BC6BDD8BFB2C8151257032ECD8B"
expect resp.http.abc == "3A985DA74FE225B2045C172D6BD390BD855F086E3E9D525B46BFE24511431532"
expect resp.http.msgdigest == "EDCDB2069366E75243860C18C3A11465ECA34BCE6143D30C8665CEFCFD32BFFD"
expect resp.http.alphalc == "7CAB2DC765E21B241DBC1C255CE620B29F527C6D5E7F5F843E56288F0D707521"
expect resp.http.alphanum == "A79D6A9DA47F04A3B9A9323EC9991F2105D4C78A7BC7BEEB103855A7A11DFB9F"
expect resp.http.digits == "293E5CE4CE54EE71990AB06E511B7CCD62722B1BEB414F5FF65C8274E0F5BE1D"
expect resp.http.pangram == "69070DDA01975C8C120C3AADA1B282394E7F032FA9CF32F4CB2259A0897DFC04"
# from http://www.di-mgt.com.au/sha_testvectors.html
expect resp.http.alphasoup == "41c0dba2a9d6240849100376a8235e2c82e1b9998a999e21db32dd97496d3376"
# verified with: base64 -d | rhash --sha3-256 -
expect resp.http.allbytes == "06b0a7c8b08fa1e1a3d21cee0b32c05fc193452d2a6b7222a9501a9f745b5daa"
# cf. http://wolfgang-ehrhardt.de/hmac-sha3-testvectors.html
expect resp.http.ehrhardt1 == "ba85192310dffa96e2a3a40e69774351140bb7185e1202cdcc917589f95e16bb"
expect resp.http.ehrhardt2 == "c7d4072e788877ae3596bbb0da73b887c9171f93095b294ae857fbe2645e1ba5"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment