From 31d47836a731b5221de50cee2c49dcf065b3f66e Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 7 Nov 2018 02:52:17 +0000 Subject: [PATCH] Test fenceposts in chacha core primitives. --- tests/microcode/test-chacha.scm | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/microcode/test-chacha.scm b/tests/microcode/test-chacha.scm index 8323fa266..598563c32 100644 --- a/tests/microcode/test-chacha.scm +++ b/tests/microcode/test-chacha.scm @@ -67,4 +67,30 @@ USA. #xda #x41 #x59 #x7c #x51 #x57 #x48 #x8d #x77 #x24 #xe0 #x3f #xb8 #xd8 #x4a #x37 #x6a #x43 #xb8 #xf4 #x15 #x18 #xa1 #x1c - #xc3 #x87 #xb6 #x69 #xb2 #xee #x65 #x86)) \ No newline at end of file + #xc3 #x87 #xb6 #x69 #xb2 #xee #x65 #x86)) + +(define (define-chacha-fencepost-test name) + (define-test (symbol 'chacha-fencepost/ name) + (lambda () + (let ((output (make-bytevector 65)) + (input (make-bytevector 16 0)) + (key (make-bytevector 32 0)) + (constant (string->utf8 "expand 32-byte k")) + (primitive (make-primitive-procedure name 5))) + (define (zv n) (make-bytevector n 0)) + (primitive output 0 input key constant) + (primitive output 1 input key constant) + (assert-error (lambda () (primitive output -1 input key constant))) + (assert-error (lambda () (primitive output 2 input key constant))) + (assert-error (lambda () (primitive output 3 input key constant))) + (assert-error (lambda () (primitive output 64 input key constant))) + (assert-error (lambda () (primitive output 0 (zv 15) key constant))) + (assert-error (lambda () (primitive output 0 (zv 17) key constant))) + (assert-error (lambda () (primitive output 0 input (zv 31) constant))) + (assert-error (lambda () (primitive output 0 input (zv 33) constant))) + (assert-error (lambda () (primitive output 0 input key (zv 15)))) + (assert-error (lambda () (primitive output 0 input key (zv 17)))))))) + +(define-chacha-fencepost-test 'chacha8-core) +(define-chacha-fencepost-test 'chacha12-core) +(define-chacha-fencepost-test 'chacha20-core) \ No newline at end of file -- 2.25.1