Coverage report: /home/ellis/comp/ext/ironclad/src/ciphers/xsalsa20.lisp

KindCoveredAll%
expression0110 0.0
branch02 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;;; xsalsa20.lisp -- implementation of the XSalsa20 stream cipher
2
 (in-package :crypto)
3
 
4
 (defclass xsalsa20 (salsa20)
5
   ())
6
 
7
 (defclass xsalsa20/12 (xsalsa20)
8
   ()
9
   (:default-initargs :core-function #'salsa20/12-core))
10
 
11
 (defclass xsalsa20/8 (xsalsa20)
12
   ()
13
   (:default-initargs :core-function #'salsa20/8-core))
14
 
15
 (defmethod shared-initialize :after ((cipher xsalsa20) slot-names
16
                                      &rest initargs
17
                                      &key (key nil key-p)
18
                                      (initialization-vector nil iv-p)
19
                                      &allow-other-keys)
20
   (declare (ignore initargs key key-p iv-p))
21
   (let ((state (salsa20-state cipher))
22
         (buffer (make-array 64 :element-type '(unsigned-byte 8))))
23
     (declare (type salsa20-state state)
24
              (type salsa20-keystream-buffer buffer))
25
     (when initialization-vector
26
       (when (< (length initialization-vector) 24)
27
         (error 'invalid-initialization-vector
28
                :cipher (class-name (class-of cipher))
29
                :block-length 24))
30
       (setf (aref state 8) (ub32ref/le initialization-vector 8)
31
             (aref state 9) (ub32ref/le initialization-vector 12)))
32
     (funcall (salsa20-core-function cipher) buffer state)
33
     (setf (aref state 1) (mod32- (ub32ref/le buffer 0) (aref state 0))
34
           (aref state 2) (mod32- (ub32ref/le buffer 20) (aref state 5))
35
           (aref state 3) (mod32- (ub32ref/le buffer 40) (aref state 10))
36
           (aref state 4) (mod32- (ub32ref/le buffer 60) (aref state 15))
37
           (aref state 11) (mod32- (ub32ref/le buffer 24) (aref state 6))
38
           (aref state 12) (mod32- (ub32ref/le buffer 28) (aref state 7))
39
           (aref state 13) (mod32- (ub32ref/le buffer 32) (aref state 8))
40
           (aref state 14) (mod32- (ub32ref/le buffer 36) (aref state 9))
41
           (aref state 8) 0
42
           (aref state 9) 0)
43
     (if initialization-vector
44
         (setf (aref state 6) (ub32ref/le initialization-vector 16)
45
               (aref state 7) (ub32ref/le initialization-vector 20))
46
         (setf (aref state 6) 0
47
               (aref state 7) 0)))
48
   cipher)
49
 
50
 (defcipher xsalsa20
51
   (:mode :stream)
52
   (:crypt-function salsa20-crypt)
53
   (:key-length (:fixed 16 32)))
54
 
55
 (defcipher xsalsa20/12
56
   (:mode :stream)
57
   (:crypt-function salsa20-crypt)
58
   (:key-length (:fixed 16 32)))
59
 
60
 (defcipher xsalsa20/8
61
   (:mode :stream)
62
   (:crypt-function salsa20-crypt)
63
   (:key-length (:fixed 16 32)))