Changeset 13195 in project


Ignore:
Timestamp:
02/07/09 02:28:56 (11 years ago)
Author:
Alaric Snell-Pym
Message:

V1.1 (crypto tools split out)

Location:
release/3/aes/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/3/aes/trunk/aes.scm

    r13161 r13195  
    1 (use lolevel)
    2 
    3 (declare (export blob->hexstring blob->hexstring/uppercase hexstring->blob
     1
     2(declare (export
    43   make-aes128-encryptor make-aes192-encryptor make-aes256-encryptor
    54   make-aes128-decryptor make-aes192-decryptor make-aes256-decryptor))
     
    13231322            result))))
    13241323
    1325 (define (blob->hexstring blob)
    1326    (let ((str (make-string (* 2 (blob-size blob)))))
    1327       ((foreign-lambda* void ((blob in) (int in_len) ((c-pointer char) out)) "
    1328          while (in_len--) {
    1329             *out++ = \"0123456789abcdef\"[(*in) >> 4];
    1330             *out++ = \"0123456789abcdef\"[(*in) & 0x0f];
    1331             in++;
    1332          }
    1333          ") blob (blob-size blob) (make-locative str))
    1334       str))
    1335 
    1336 (define (blob->hexstring/uppercase blob)
    1337    (let ((str (make-string (* 2 (blob-size blob)))))
    1338       ((foreign-lambda* void ((blob in) (int in_len) ((c-pointer char) out)) "
    1339          while (in_len--) {
    1340             *out++ = \"0123456789ABCDEF\"[(*in) >> 4];
    1341             *out++ = \"0123456789ABCDEF\"[(*in) & 0x0f];
    1342             in++;
    1343          }
    1344          ") blob (blob-size blob) (make-locative str))
    1345       str))
    1346 
    1347 (define (hexstring->blob string)
    1348    (if (odd? (string-length string))
    1349       (error "hexstring->blob: The supplied string must have an even length"))
    1350    
    1351    (let ((blob (make-blob (/ (string-length string) 2))))
    1352       (if ((foreign-lambda* bool (((c-pointer char) in) (int in_len) (blob out)) "
    1353          while (in_len) {
    1354             if (*in >= '0' && *in <= '9') *out = (*in - '0') << 4;
    1355             else if (*in >= 'A' && *in <= 'F') *out = (*in - 'A' + 10) << 4;
    1356             else if (*in >= 'a' && *in <= 'f') *out = (*in - 'a' + 10) << 4;
    1357             else C_return(1);
    1358             in++;
    1359            
    1360             if (*in >= '0' && *in <= '9') *out |= (*in - '0');
    1361             else if (*in >= 'A' && *in <= 'F') *out |= (*in - 'A' + 10);
    1362             else if (*in >= 'a' && *in <= 'f') *out |= (*in - 'a' + 10);
    1363             else C_return(1);
    1364             in++;
    1365            
    1366             out++;
    1367            
    1368             in_len -= 2;
    1369          }
    1370          C_return(0);
    1371          ") (make-locative string) (string-length string) blob)
    1372          (error "hexstring->blob: Invalid character(s) in input string")
    1373          blob)))
    1374            
     1324                 
  • release/3/aes/trunk/aes.setup

    r13161 r13195  
    55  'aes
    66  '("aes.o" "aes.so" "aes.html")
    7   '((version 1.0)
     7  '((version 1.1)
    88    (static "aes.o") ;; for static linking
    99    (documentation "aes.html")))
  • release/3/aes/trunk/test/run.scm

    r13161 r13195  
    11(use aes)
    2 
    3 (define hexstring1 (blob->hexstring (hexstring->blob "0123456789ABCDEF")))
    4 (printf "Hex1: ~A\n" hexstring1)
    5 (assert (string=? hexstring1 "0123456789abcdef"))
    6 
    7 (define hexstring2 (blob->hexstring/uppercase (hexstring->blob "0123456789ABCDEF")))
    8 (printf "Hex2: ~A\n" hexstring2)
    9 (assert (string=? hexstring2 "0123456789ABCDEF"))
    10 
     2(use crypto-tools)
    113
    124(let*
     
    6153   (assert (string=? encrypted-string "080E9517EB1677719ACF728086040AE3"))
    6254   (assert (string=? decrypted-string "069A007FC76A459F98BAF917FEDF9521")))
    63 
Note: See TracChangeset for help on using the changeset viewer.