Ignore:
Timestamp:
02/09/09 13:31:09 (12 years ago)
Author:
Alaric Snell-Pym
Message:

V1.1: cbc* mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/crypto-tools/trunk/test/run.scm

    r13197 r13221  
    3030(test-padding "4" "abcdefghijklmno")
    3131
    32 (define (dummy-encryptor l) l)
    33 (define (dummy-decryptor l) l)
     32(define dummy-key (hexstring->blob "01010101010101010101010101010101"))
     33(define (dummy-encryptor l) (blob-xor l dummy-key))
     34(define dummy-decryptor dummy-encryptor)
    3435
    3536(define (test-cbc name string)
     
    5556(test-cbc "11" "123456789012345") ; 1 block - 1
    5657(test-cbc "12" "1234567890123456123456789012345") ; 2 blocks - 1
     58
     59(define (test-cbc* name string)
     60   (let*
     61      ((encryptor dummy-encryptor)
     62       (decryptor dummy-decryptor)
     63       (cbc-encryptor (make-cbc*-encryptor encryptor 16))
     64       (cbc-decryptor (make-cbc*-decryptor decryptor 16))
     65       (test-input (string->blob string))
     66       (encrypted (cbc-encryptor test-input (hexstring->blob "00010203050607080A0B0C0D0F101112")))
     67       (decrypted (cbc-decryptor encrypted)))
     68   
     69      (printf "Test vector ~Aa: ~A\n" name (blob->hexstring/uppercase encrypted))
     70      (printf "Test vector ~Ab: <~A>\n" name (blob->string decrypted))
     71      (assert (blob=? test-input decrypted))))
     72
     73(test-cbc* "13" "") ; Zero bytes
     74(test-cbc* "14" "a") ; One byte
     75(test-cbc* "15" "1234567890123456") ; 1 block exactly
     76(test-cbc* "16" "12345678901234561234567890123456") ; 2 blocks exactly
     77(test-cbc* "17" "1234567890123456X") ; 1 block + 1
     78(test-cbc* "18" "12345678901234561234567890123456X") ; 2 blocks + 1
     79(test-cbc* "19" "123456789012345") ; 1 block - 1
     80(test-cbc* "20" "1234567890123456123456789012345") ; 2 blocks - 1
     81
Note: See TracChangeset for help on using the changeset viewer.