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

KindCoveredAll%
expression091 0.0
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;;; tea.lisp
2
 (in-package :crypto)
3
 
4
 (defconstant +tea-n-rounds+ 32)
5
 (defconstant +tea-delta+ #x9e3779b9)
6
 
7
 (defclass tea (cipher 8-byte-block-mixin)
8
   ((key :accessor key)))
9
 
10
 (define-block-encryptor tea 8
11
   (with-words ((y z) plaintext plaintext-start)
12
     (let ((key (key context))
13
           (sum 0))
14
       (declare (type (simple-array (unsigned-byte 32) (4)) key))
15
       (declare (type (unsigned-byte 32) sum))
16
       ;; could probably unroll this loop for reasonable performance gain
17
       (dotimes (i +tea-n-rounds+)
18
         (setf sum (mod32+ sum +tea-delta+))
19
         (setf y (mod32+ y (logxor (mod32+ (mod32ash z 4) (aref key 0))
20
                                   (mod32+ z sum)
21
                                   (mod32+ (mod32ash z -5) (aref key 1)))))
22
         (setf z (mod32+ z (logxor (mod32+ (mod32ash y 4) (aref key 2))
23
                                   (mod32+ y sum)
24
                                   (mod32+ (mod32ash y -5) (aref key 3))))))
25
       (store-words ciphertext ciphertext-start y z))))
26
 
27
 (define-block-decryptor tea 8
28
   (with-words ((y z) ciphertext ciphertext-start)
29
     (let ((key (key context))
30
           (sum (mod32ash +tea-delta+ 5)))
31
       (declare (type (simple-array (unsigned-byte 32) (4)) key))
32
       (declare (type (unsigned-byte 32) sum))
33
       (dotimes (i +tea-n-rounds+)
34
         (setf z (mod32- z (logxor (mod32+ (mod32ash y 4) (aref key 2))
35
                                   (mod32+ y sum)
36
                                   (mod32+ (mod32ash y -5) (aref key 3)))))
37
         (setf y (mod32- y (logxor (mod32+ (mod32ash z 4) (aref key 0))
38
                                   (mod32+ z sum)
39
                                   (mod32+ (mod32ash z -5) (aref key 1)))))
40
         (setf sum (mod32- sum +tea-delta+)))
41
       (store-words plaintext plaintext-start y z))))
42
 
43
 (defmethod schedule-key ((cipher tea) key)
44
   (let ((ub32key (make-array 4 :element-type '(unsigned-byte 32))))
45
     (with-words ((a b c d) key 0)
46
       (setf (aref ub32key 0) a
47
             (aref ub32key 1) b
48
             (aref ub32key 2) c
49
             (aref ub32key 3) d)
50
       (setf (key cipher) ub32key)
51
       cipher)))
52
 
53
 (defcipher tea
54
   (:encrypt-function tea-encrypt-block)
55
   (:decrypt-function tea-decrypt-block)
56
   (:block-length 8)
57
   (:key-length (:fixed 16)))