source: project/release/4/sha2/trunk/sha2.scm @ 15620

Last change on this file since 15620 was 15620, checked in by Kon Lovett, 10 years ago

Has been using wrong procs & constants in some routines.

File size: 3.3 KB
Line 
1;;;; sha2.scm
2
3(module sha2 (;export
4  sha256-binary-digest sha384-binary-digest sha512-binary-digest
5  sha256-digest sha384-digest sha512-digest
6  sha256-primitive sha384-primitive sha512-primitive)
7
8  (import chicken scheme foreign)
9  (require-extension message-digest)
10
11  (declare
12    (fixnum)
13    (no-procedure-checks) )
14
15#>
16#define SHA2_USE_INTTYPES_H 1
17#define SHA2_USE_MEMSET_MEMCPY 1
18#define SHA2_LITTLE_ENDIAN 1234
19#define SHA2_BIG_ENDIAN    4321
20#ifdef C_BIG_ENDIAN
21# define SHA2_BYTE_ORDER SHA2_BIG_ENDIAN
22#endif
23#ifdef C_LITTLE_ENDIAN
24# define SHA2_BYTE_ORDER SHA2_LITTLE_ENDIAN
25#endif
26
27#include "sha2-base.c"
28
29#undef SHA2_LITTLE_ENDIAN
30#undef SHA2_BIG_ENDIAN
31#undef SHA2_BYTE_ORDER
32#undef SHA2_USE_MEMSET_MEMCPY
33#undef SHA2_USE_INTTYPES_H
34<#
35
36;;; 256
37
38(define-foreign-variable context-size-256 int "sizeof(SHA256_CTX)")
39
40(define sha256-init (foreign-lambda void "SHA256_Init" c-pointer))
41(define sha256-update (foreign-lambda void "SHA256_Update" c-pointer pointer int))
42(define sha256-final (foreign-lambda void "SHA256_Final" c-pointer pointer))
43
44(define-constant digest-length-256 32) ; SHA256_DIGEST_LENGTH
45
46(define (sha256-binary-digest obj)
47  (make-binary-message-digest obj
48    context-size-256 digest-length-256
49    sha256-init sha256-update sha256-final
50    'sha256-binary-digest))
51
52(define (sha256-digest obj)
53  (make-message-digest obj
54    context-size-256 digest-length-256
55    sha256-init sha256-update sha256-final
56    'sha256-digest))
57
58(define (sha256-primitive)
59  (make-message-digest-primitive
60    context-size-256 digest-length-256
61    sha256-init sha256-update sha256-final
62    'sha256-primitive))
63
64;;; 384
65
66(define-foreign-variable context-size-384 int "sizeof(SHA384_CTX)")
67
68(define sha384-init (foreign-lambda void "SHA384_Init" c-pointer))
69(define sha384-update (foreign-lambda void "SHA384_Update" c-pointer pointer int))
70(define sha384-final (foreign-lambda void "SHA384_Final" c-pointer pointer))
71
72(define-constant digest-length-384 48) ; SHA384_DIGEST_LENGTH
73
74(define (sha384-binary-digest obj)
75  (make-binary-message-digest obj
76    context-size-384 digest-length-384
77    sha384-init sha384-update sha384-final
78    'sha384-binary-digest))
79
80(define (sha384-digest obj)
81  (make-message-digest obj
82    context-size-384 digest-length-384
83    sha384-init sha384-update sha384-final
84    'sha384-digest))
85
86(define (sha384-primitive)
87  (make-message-digest-primitive
88    context-size-384 digest-length-384
89    sha384-init sha384-update sha384-final
90    'sha384-primitive))
91
92;;; 512
93
94(define-foreign-variable context-size-512 int "sizeof(SHA512_CTX)")
95
96(define sha512-init (foreign-lambda void "SHA512_Init" c-pointer))
97(define sha512-update (foreign-lambda void "SHA512_Update" c-pointer pointer int))
98(define sha512-final (foreign-lambda void "SHA512_Final" c-pointer pointer))
99
100(define-constant digest-length-512 64) ; SHA512_DIGEST_LENGTH
101
102(define (sha512-binary-digest obj)
103  (make-binary-message-digest obj
104    context-size-512 digest-length-512
105    sha512-init sha512-update sha512-final
106    'sha512-binary-digest))
107
108(define (sha512-digest obj)
109  (make-message-digest obj
110    context-size-512 digest-length-512
111    sha512-init sha512-update sha512-final
112    'sha512-digest))
113
114(define (sha512-primitive)
115  (make-message-digest-primitive
116    context-size-512 digest-length-512
117    sha512-init sha512-update sha512-final
118    'sha512-primitive))
119
120) ;module sha2
Note: See TracBrowser for help on using the repository browser.