Commits

evhan committed 6125ed7

enforce 16-byte keys

Comments (0)

Files changed (1)

          ((zero? i))
        (begin . b)))))
 
+(define-syntax assert
+  (syntax-rules ()
+    ((_ t)   (or t (error "assertion failed" 't)))
+    ((_ t m) (or t (error (string-append "assertion failed: " m) 't)))))
+
 ;; Treats `v` as little-endian.
 (define bytevector->integer
   (case-lambda
         (m3 (string->number "7465646279746573" 16)))
     (lambda (c d)
       (define (siphash-c-d k)
+        (assert (= (bytevector-length k) 16) "key must be 16 bytes")
         (let* ((k0 (bytevector->integer (bytevector-copy k 0 8) 8))
                (k1 (bytevector->integer (bytevector-copy k 8 16) 8))
                (v0 (⊕ k0 m0))