1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en" />
<title>skalibs: the stdcrypto library interface</title>
<meta name="Description" content="skalibs: the stdcrypto library interface" />
<meta name="Keywords" content="skalibs stdcrypto libstdcrypto library interface" />
<!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
</head>
<body>
<p>
<a href="../libskarnet.html">libskarnet</a><br />
<a href="../index.html">skalibs</a><br />
<a href="//skarnet.org/software/">Software</a><br />
<a href="//skarnet.org/">skarnet.org</a>
</p>
<h1> The <tt>stdcrypto</tt> library interface </h1>
<p>
<tt>stdcrypto</tt> is a small collection of standard,
public-domain cryptographic primitives. Currently, the following
operations are provided:
</p>
<ul>
<li> sha1 </li>
<li> sha256 </li>
<li> sha512 </li>
<li> blake2s </li>
<li> crc32c </li>
</ul>
<p>
Please bear in mind that sha1 is practically broken.
Do not use it in security-critical applications.
</p>
<h2> Compiling </h2>
<ul>
<li> Use <tt>#include <skalibs/stdcrypto.h></tt> </li>
</ul>
<h2> Programming </h2>
<p>
You should refer to the <tt>skalibs/stdcrypto.h</tt> header and included headers
for the exact function prototypes.
</p>
<h3> <a name="sha1"></a>
SHA1 </h3>
<pre>
SHA1Schedule ctx ;
char const *message ;
size_t messagelen ;
unsigned char digest[20] ;
sha1_init(&ctx) ;
sha1_update(&ctx, message, messagelen) ;
sha1_final(&ctx, digest) ;
</pre>
<ul>
<li> <tt>sha1_init()</tt> prepares a SHA1Schedule structure for computation </li>
<li> <tt>sha1_update()</tt> adds <em>message</em> to the message to be digested </li>
<li> <tt>sha1_final()</tt> computes the digest </li>
</ul>
<h3> <a name="sha256"></a>
SHA256 </h3>
<pre>
SHA256Schedule ctx ;
char const *message ;
size_t messagelen ;
char digest[32] ;
sha256_init(&ctx) ;
sha256_update(&ctx, message, messagelen) ;
sha256_final(&ctx, digest) ;
</pre>
<ul>
<li> <tt>sha256_init()</tt> prepares a SHA256Schedule structure for computation </li>
<li> <tt>sha256_update()</tt> adds <em>message</em> to the message to be digested </li>
<li> <tt>sha256_final()</tt> computes the digest </li>
</ul>
<h3> <a name="sha512"></a>
SHA512 </h3>
<pre>
SHA512Schedule ctx ;
char const *message ;
size_t messagelen ;
char digest[64] ;
sha512_init(&ctx) ;
sha512_update(&ctx, message, messagelen) ;
sha512_final(&ctx, digest) ;
</pre>
<ul>
<li> <tt>sha512_init()</tt> prepares a SHA512Schedule structure for computation </li>
<li> <tt>sha512_update()</tt> adds <em>message</em> to the message to be digested </li>
<li> <tt>sha512_final()</tt> computes the digest </li>
</ul>
<h3> <a name="blake2s"></a>
blake2s </h3>
Same scheme as with the other hashes.
<pre>
blake2s_ctx ctx ;
char const *message ;
size_t messagelen ;
size_t outlen = 32 ; /* the user gives the length of the digest */
char digest[outlen] ;
blake2s_init(&ctx, outlen) ;
blake2s_update(&ctx, message, messagelen) ;
blake2s_final(&ctx, digest) ;
</pre>
<h3> <a name="crc32c"></a>
crc32c </h3>
This isn't a cryptography primitive, but just a function to compute
the Castagnoli version of a cyclic redundancy code.
<pre>
uint32_t crc = 0 ; /* no need for context except that crc needs to be initialized to 0 */
char const *message ;
size_t messagelen ;
crc = crc32c(crc, message, messagelen) ;
</pre>
</body>
</html>
|