Commit bd7d2d01 authored by Geoff Simmons's avatar Geoff Simmons

restructure md5.vtc

parent 2967d9cb
Pipeline #44 skipped
......@@ -10,48 +10,17 @@ varnish v1 -vcl {
backend b { .host = "${bad_ip}"; }
sub vcl_init {
# RFC2202 test cases
new k1 = blobcode.blob(HEX, "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
new rfc2202t1 = blobdigest.hmac(MD5, k1.get());
new k2 = blobcode.blob(IDENTITY, "Jefe");
new rfc2202t2 = blobdigest.hmac(MD5, k2.get());
new k3 = blobcode.blob(HEX, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new rfc2202t3 = blobdigest.hmac(MD5, k3.get());
new k4 = blobcode.blob(HEX,
"0102030405060708090a0b0c0d0e0f10111213141516171819");
new rfc2202t4 = blobdigest.hmac(MD5, k4.get());
new k5 = blobcode.blob(HEX, "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c");
new rfc2202t5 = blobdigest.hmac(MD5, k5.get());
new k6 = blobcode.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new rfc2202t6 = blobdigest.hmac(MD5, k6.get());
new d1 = blobdigest.digest(MD5);
new d2 = blobdigest.digest(MD5);
new a = blobcode.blob(IDENTITY, "a");
new d3 = blobdigest.digest(MD5, a.get());
new msg = blobcode.blob(IDENTITY, "message");
new d4 = blobdigest.digest(MD5, msg.get());
new alphalc = blobcode.blob(IDENTITY,
"abcdefghijklmnopqrstuvwxyz");
new d5 = blobdigest.digest(MD5, alphalc.get());
new empty = blobcode.blob(IDENTITY, "");
new d6 = blobdigest.digest(MD5, empty.get());
new alphauc = blobcode.blob(IDENTITY,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
new d7 = blobdigest.digest(MD5, alphauc.get());
new digits = blobcode.blob(IDENTITY, "1234567890");
new d8 = blobdigest.digest(MD5, digits.get());
new pangram =
blobcode.blob(IDENTITY,
"The quick brown fox jumps over the lazy dog");
new d9 = blobdigest.digest(MD5, pangram.get());
new d10 = blobdigest.digest(MD5, pangram.get());
# Byte values 0 to 63, 64 to 127, etc up to 255
new b0to63 = blobcode.blob(BASE64,
......@@ -62,6 +31,17 @@ varnish v1 -vcl {
"gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+vw==");
new b192to255 = blobcode.blob(BASE64,
"wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==");
new d1 = blobdigest.digest(MD5);
new d2 = blobdigest.digest(MD5);
new d3 = blobdigest.digest(MD5, a.get());
new d4 = blobdigest.digest(MD5, msg.get());
new d5 = blobdigest.digest(MD5, alphalc.get());
new d6 = blobdigest.digest(MD5, empty.get());
new d7 = blobdigest.digest(MD5, alphauc.get());
new d8 = blobdigest.digest(MD5, digits.get());
new d9 = blobdigest.digest(MD5, pangram.get());
new d10 = blobdigest.digest(MD5, pangram.get());
new d11 = blobdigest.digest(MD5, b0to63.get());
}
......@@ -178,6 +158,7 @@ varnish v1 -vcl {
}
set resp.http.allbytes = blobcode.encode(HEXLC, d11.final());
# Tests for the hash() function
set resp.http.emptyf
= blobcode.encode(HEXUC, blobdigest.hash(MD5, empty.get()));
......@@ -229,45 +210,6 @@ varnish v1 -vcl {
= blobcode.encode(HEXLC, blobdigest.hash(MD5,
blobcode.decode(BASE64,
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==")));
set resp.http.rfc2202t1 = blobcode.encode(HEXLC,
rfc2202t1.hmac(blobcode.decode(IDENTITY, "Hi There")));
set resp.http.rfc2202t2
= blobcode.encode(HEXLC,
rfc2202t2.hmac(blobcode.decode(IDENTITY,
"what do ya want for nothing?")));
set resp.http.rfc2202t3
= blobcode.encode(HEXLC,
rfc2202t3.hmac(blobcode.decode(HEX,
"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd")));
set resp.http.rfc2202t4
= blobcode.encode(HEXLC,
rfc2202t4.hmac(blobcode.decode(HEX,
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd")));
set resp.http.rfc2202t5
= blobcode.encode(HEXLC,
rfc2202t5.hmac(blobcode.decode(IDENTITY,
"Test With Truncation")));
set resp.http.rfc2202t6
= blobcode.encode(HEXLC,
rfc2202t6.hmac(blobcode.decode(IDENTITY,
"Test Using Larger Than Block-Size Key - Hash Key First")));
/*
* Test case 7 uses the same key as 6, so we'll re-use
* object rfc2202t6. This tests repeated use of the same
* internal hash contexts.
*/
set resp.http.rfc2202t7
= blobcode.encode(HEXLC,
rfc2202t6.hmac(blobcode.decode(IDENTITY,
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data")));
}
} -start
......@@ -303,15 +245,6 @@ client c1 {
# verified with: base64 -d | md5sum
expect resp.http.allbytes == "e2c865db4162bed963bfaa9ef6ac18f0"
expect resp.http.allbytesf == "e2c865db4162bed963bfaa9ef6ac18f0"
# RFC2202 test cases
expect resp.http.rfc2202t1 == "9294727a3638bb1c13f48ef8158bfc9d"
expect resp.http.rfc2202t2 == "750c783e6ab0b503eaa86e310a5db738"
expect resp.http.rfc2202t3 == "56be34521d144c88dbb8c733f0e8b3f6"
expect resp.http.rfc2202t4 == "697eaf0aca3a3aea3a75164746ffaa79"
expect resp.http.rfc2202t5 == "56461ef2342edc00f9bab995690efd4c"
expect resp.http.rfc2202t6 == "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
expect resp.http.rfc2202t7 == "6f630fad67cda0ee1fb1f562db3aa53e"
} -run
# Test re-use of digest objects in backend and client contexts
......@@ -400,3 +333,93 @@ client c1 -repeat 10 {
expect resp.http.pangram == "9e107d9d372bb6826bd81d3542a419d6"
expect resp.http.pangramperiod == "e4d909c290d0fb1ca068ffaddf22cbd0"
} -run
# hmac object
varnish v1 -vcl {
import blobdigest from "${vmod_topbuild}/src/.libs/libvmod_blobdigest.so";
import blobcode;
backend b { .host = "${bad_ip}"; }
sub vcl_init {
# RFC2202 test cases
new k1 = blobcode.blob(HEX, "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
new rfc2202t1 = blobdigest.hmac(MD5, k1.get());
new k2 = blobcode.blob(IDENTITY, "Jefe");
new rfc2202t2 = blobdigest.hmac(MD5, k2.get());
new k3 = blobcode.blob(HEX, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new rfc2202t3 = blobdigest.hmac(MD5, k3.get());
new k4 = blobcode.blob(HEX,
"0102030405060708090a0b0c0d0e0f10111213141516171819");
new rfc2202t4 = blobdigest.hmac(MD5, k4.get());
new k5 = blobcode.blob(HEX, "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c");
new rfc2202t5 = blobdigest.hmac(MD5, k5.get());
new k6 = blobcode.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
new rfc2202t6 = blobdigest.hmac(MD5, k6.get());
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.rfc2202t1 = blobcode.encode(HEXLC,
rfc2202t1.hmac(blobcode.decode(IDENTITY, "Hi There")));
set resp.http.rfc2202t2
= blobcode.encode(HEXLC,
rfc2202t2.hmac(blobcode.decode(IDENTITY,
"what do ya want for nothing?")));
set resp.http.rfc2202t3
= blobcode.encode(HEXLC,
rfc2202t3.hmac(blobcode.decode(HEX,
"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd")));
set resp.http.rfc2202t4
= blobcode.encode(HEXLC,
rfc2202t4.hmac(blobcode.decode(HEX,
"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd")));
set resp.http.rfc2202t5
= blobcode.encode(HEXLC,
rfc2202t5.hmac(blobcode.decode(IDENTITY,
"Test With Truncation")));
set resp.http.rfc2202t6
= blobcode.encode(HEXLC,
rfc2202t6.hmac(blobcode.decode(IDENTITY,
"Test Using Larger Than Block-Size Key - Hash Key First")));
/*
* Test case 7 uses the same key as 6, so we'll re-use
* object rfc2202t6. This tests repeated use of the same
* internal hash contexts.
*/
set resp.http.rfc2202t7
= blobcode.encode(HEXLC,
rfc2202t6.hmac(blobcode.decode(IDENTITY,
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data")));
}
}
client c1 {
txreq
rxresp
expect resp.status == 200
# RFC2202 test cases
expect resp.http.rfc2202t1 == "9294727a3638bb1c13f48ef8158bfc9d"
expect resp.http.rfc2202t2 == "750c783e6ab0b503eaa86e310a5db738"
expect resp.http.rfc2202t3 == "56be34521d144c88dbb8c733f0e8b3f6"
expect resp.http.rfc2202t4 == "697eaf0aca3a3aea3a75164746ffaa79"
expect resp.http.rfc2202t5 == "56461ef2342edc00f9bab995690efd4c"
expect resp.http.rfc2202t6 == "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
expect resp.http.rfc2202t7 == "6f630fad67cda0ee1fb1f562db3aa53e"
} -run
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