source: project/release/5/sha2/trunk/sha2.scm @ 35856

Last change on this file since 35856 was 35856, checked in by Kon Lovett, 2 years ago

C5 initial

File size: 3.4 KB
Line 
1;;;; sha2.scm
2
3#>
4#define SHA2_USE_INTTYPES_H 1
5#define SHA2_USE_MEMSET_MEMCPY 1
6#define SHA2_LITTLE_ENDIAN 1234
7#define SHA2_BIG_ENDIAN    4321
8#ifdef C_BIG_ENDIAN
9# define SHA2_BYTE_ORDER SHA2_BIG_ENDIAN
10#endif
11#ifdef C_LITTLE_ENDIAN
12# define SHA2_BYTE_ORDER SHA2_LITTLE_ENDIAN
13#endif
14
15#include "sha2-base.c"
16
17#undef SHA2_LITTLE_ENDIAN
18#undef SHA2_BIG_ENDIAN
19#undef SHA2_BYTE_ORDER
20#undef SHA2_USE_MEMSET_MEMCPY
21#undef SHA2_USE_INTTYPES_H
22<#
23
24(module sha2
25
26(;exports
27  sha256-primitive sha384-primitive sha512-primitive)
28
29(import scheme
30  (chicken base)
31  (chicken foreign)
32  message-digest-primitive)
33
34;;; 256
35
36(define-foreign-variable context-size-256 int "sizeof(SHA256_CTX)")
37(define-foreign-variable digest-length-256 int "SHA256_DIGEST_LENGTH")
38(define-foreign-variable block-length-256 int "SHA256_BLOCK_LENGTH")
39
40(define sha256-init (foreign-lambda void "SHA256_Init" c-pointer))
41(define sha256-update (foreign-lambda void "SHA256_Update" c-pointer scheme-pointer int))
42(define sha256-final (foreign-lambda void "SHA256_Final" c-pointer scheme-pointer))
43(define sha256-raw-update (foreign-lambda void "SHA256_Update" c-pointer c-pointer int))
44
45(define sha256-primitive
46  (let ((the-sha256-primitive #f))
47    (lambda ()
48      (unless the-sha256-primitive
49        (set! the-sha256-primitive
50              (make-message-digest-primitive
51                context-size-256 digest-length-256 sha256-init sha256-update sha256-final
52                #:block-length block-length-256 #:raw-update sha256-raw-update #:name 'sha256)) )
53      the-sha256-primitive ) ) )
54
55;;; 384
56
57(define-foreign-variable context-size-384 int "sizeof(SHA384_CTX)")
58(define-foreign-variable digest-length-384 int "SHA384_DIGEST_LENGTH")
59(define-foreign-variable block-length-384 int "SHA384_BLOCK_LENGTH")
60
61(define sha384-init (foreign-lambda void "SHA384_Init" c-pointer))
62(define sha384-update (foreign-lambda void "SHA384_Update" c-pointer scheme-pointer int))
63(define sha384-final (foreign-lambda void "SHA384_Final" c-pointer scheme-pointer))
64(define sha384-raw-update (foreign-lambda void "SHA384_Update" c-pointer c-pointer int))
65
66(define sha384-primitive
67  (let ((the-sha384-primitive #f))
68    (lambda ()
69      (unless the-sha384-primitive
70        (set! the-sha384-primitive
71              (make-message-digest-primitive
72                context-size-384 digest-length-384 sha384-init sha384-update sha384-final
73                #:block-length block-length-384 #:raw-update sha384-raw-update #:name 'sha384)) )
74      the-sha384-primitive ) ) )
75
76;;; 512
77
78(define-foreign-variable context-size-512 int "sizeof(SHA512_CTX)")
79(define-foreign-variable digest-length-512 int "SHA512_DIGEST_LENGTH")
80(define-foreign-variable block-length-512 int "SHA512_BLOCK_LENGTH")
81
82(define sha512-init (foreign-lambda void "SHA512_Init" c-pointer))
83(define sha512-update (foreign-lambda void "SHA512_Update" c-pointer scheme-pointer int))
84(define sha512-final (foreign-lambda void "SHA512_Final" c-pointer scheme-pointer))
85(define sha512-raw-update (foreign-lambda void "SHA512_Update" c-pointer c-pointer int))
86
87(define sha512-primitive
88  (let ((the-sha512-primitive #f))
89    (lambda ()
90      (unless the-sha512-primitive
91        (set! the-sha512-primitive
92              (make-message-digest-primitive
93                context-size-512 digest-length-512 sha512-init sha512-update sha512-final
94                #:block-length block-length-512 #:raw-update sha512-raw-update #:name 'sha512)) )
95      the-sha512-primitive ) ) )
96
97) ;module sha2
Note: See TracBrowser for help on using the repository browser.