-
Notifications
You must be signed in to change notification settings - Fork 1
/
fortium.f90
193 lines (155 loc) · 9.98 KB
/
fortium.f90
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
module fortium
!Fortran bindings for libsodium - a P(ortable|ackageable) NaCl-based crypto library
!(https://github.com/jedisct1/libsodium)
!"libsodium" is licensed under the ISC license (http://en.wikipedia.org/wiki/ISC_license)
!
!fortium bindings for libsodium - MIT License (MIT)
!See LICENSE file for more details
!Copyright (c) 2014 John N. Shahbazian
!https://github.com/jshahbazi/fortium
use iso_c_binding
implicit none
interface
!----------------------------
!core.h
integer(c_size_t) function sodium_init() bind(c,name="sodium_init")
use iso_c_binding
end function sodium_init
!----------------------------
!crypt_auth.h
integer(c_size_t) function crypto_auth_bytes() bind(c,name="crypto_auth_bytes")
use iso_c_binding
end function crypto_auth_bytes
integer(c_size_t) function crypto_auth_keybytes() bind(c,name="crypto_auth_keybytes")
use iso_c_binding
end function crypto_auth_keybytes
type(c_ptr) function crypto_auth_primitive() bind(c,name="crypto_auth_primitive")
use iso_c_binding
end function crypto_auth_primitive
integer(c_int) function crypto_auth(out, in, inlen, k) bind(c,name="crypto_auth")
use iso_c_binding
type(c_ptr), value :: out !unsigned char *out
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
type(c_ptr), value, intent(in) :: k !const unsigned char *in
end function crypto_auth
integer(c_int) function crypto_auth_verify(h, in, inlen, k) bind(c,name="crypto_auth_verify")
use iso_c_binding
type(c_ptr), value, intent(in) :: h !const unsigned char *h
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
type(c_ptr), value, intent(in) :: k !const unsigned char *k
end function crypto_auth_verify
!-----------------------------
!crypto_hash_sha512.h
integer(c_size_t) function crypto_hash_sha512_bytes() bind(c,name="crypto_hash_sha512_bytes")
use iso_c_binding
end function crypto_hash_sha512_bytes
integer(c_int) function crypto_hash_sha512(out, in, inlen) bind(c,name="crypto_hash_sha512")
use iso_c_binding
type(c_ptr), value :: out !unsigned char *out
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
end function crypto_hash_sha512
integer(c_int) function crypto_hash_sha512_init(state) bind(c,name="crypto_hash_sha512_init")
use iso_c_binding
type(c_ptr), value :: state !crypto_hash_sha512_state *state
end function crypto_hash_sha512_init
integer(c_int) function crypto_hash_sha512_update(state, in, inlen) bind(c,name="crypto_hash_sha512_update")
use iso_c_binding
type(c_ptr), value :: state !crypto_hash_sha512_state *state
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inle
end function crypto_hash_sha512_update
integer(c_int) function crypto_hash_sha512_final(state, out) bind(c,name="crypto_hash_sha512_final")
use iso_c_binding
type(c_ptr), value :: state !crypto_hash_sha512_state *state
type(c_ptr), value :: out !unsigned char *out
end function crypto_hash_sha512_final
!-----------------------------
!crypto_auth_hmacsha512.h
integer(c_size_t) function crypto_auth_hmacsha512_bytes() bind(c,name="crypto_auth_hmacsha512_bytes")
use iso_c_binding
end function crypto_auth_hmacsha512_bytes
integer(c_size_t) function crypto_auth_hmacsha512_keybytes() bind(c,name="crypto_auth_hmacsha512_keybytes")
use iso_c_binding
end function crypto_auth_hmacsha512_keybytes
integer(c_int) function crypto_auth_hmacsha512(out, in, inlen, k) bind(c,name="crypto_auth_hmacsha512")
use iso_c_binding
type(c_ptr), value :: out !unsigned char *out
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
type(c_ptr), value, intent(in) :: k !const unsigned char *k
end function crypto_auth_hmacsha512
integer(c_int) function crypto_auth_hmacsha512_verify(h, in, inlen, k) bind(c,name="crypto_auth_hmacsha512_verify")
use iso_c_binding
type(c_ptr), value, intent(in) :: h !const unsigned char *h
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
type(c_ptr), value, intent(in) :: k !const unsigned char *k
end function crypto_auth_hmacsha512_verify
integer(c_int) function crypto_auth_hmacsha512_init(state, key, keylen) bind(c,name="crypto_auth_hmacsha512_init")
use iso_c_binding
type(c_ptr), value :: state !crypto_auth_hmacsha512_state *state
type(c_ptr), value, intent(in) :: key !const unsigned char *key
integer(c_size_t), value :: keylen !size_t keylen
end function crypto_auth_hmacsha512_init
integer(c_int) function crypto_auth_hmacsha512_update(state, in, inlen) bind(c,name="crypto_auth_hmacsha512_update")
use iso_c_binding
type(c_ptr), value :: state !crypto_auth_hmacsha512_state *state
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
end function crypto_auth_hmacsha512_update
integer(c_int) function crypto_auth_hmacsha512_final(state, out) bind(c,name="crypto_auth_hmacsha512_final")
use iso_c_binding
type(c_ptr), value :: state !crypto_auth_hmacsha512_state *state
type(c_ptr), value :: out !unsigned char *out
end function crypto_auth_hmacsha512_final
!-----------------------------
!crypto_auth_hmacsha512256.h
integer(c_size_t) function crypto_auth_hmacsha512256_bytes() bind(c,name="crypto_auth_hmacsha512256_bytes")
use iso_c_binding
end function crypto_auth_hmacsha512256_bytes
integer(c_size_t) function crypto_auth_hmacsha512256_keybytes() bind(c,name="crypto_auth_hmacsha512256_keybytes")
use iso_c_binding
end function crypto_auth_hmacsha512256_keybytes
integer(c_int) function crypto_auth_hmacsha512256(out, in, inlen, k) bind(c,name="crypto_auth_hmacsha512256")
use iso_c_binding
type(c_ptr),value :: out !unsigned char *out
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
type(c_ptr), value :: k !const unsigned char *k
end function crypto_auth_hmacsha512256
integer(c_int) function crypto_auth_hmacsha512256_verify(h, in, inlen, k) bind(c,name="crypto_auth_hmacsha512256_verify")
use iso_c_binding
type(c_ptr), value, intent(in) :: h !const unsigned char *h
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
type(c_ptr), value, intent(in) :: k !const unsigned char *k
end function crypto_auth_hmacsha512256_verify
integer(c_int) function crypto_auth_hmacsha512256_init(state, key, keylen) bind(c,name="crypto_auth_hmacsha512256_init")
use iso_c_binding
type(c_ptr), value :: state !crypto_auth_hmacsha512256_state *state
type(c_ptr), value, intent(in) :: key !const unsigned char *key
integer(c_size_t), value :: keylen !size_t keylen
end function crypto_auth_hmacsha512256_init
integer(c_int) function crypto_auth_hmacsha512256_update(state, in, inlen) bind(c,name="crypto_auth_hmacsha512256_update")
use iso_c_binding
type(c_ptr), value :: state !crypto_auth_hmacsha512256_state *state
type(c_ptr), value, intent(in) :: in !const unsigned char *in
integer(c_long_long), value :: inlen !unsigned long long inlen
end function crypto_auth_hmacsha512256_update
integer(c_int) function crypto_auth_hmacsha512256_final(state, out) bind(c,name="crypto_auth_hmacsha512256_final")
use iso_c_binding
type(c_ptr), value :: state !crypto_auth_hmacsha512256_state *state
type(c_ptr), value :: out !unsigned char *out
end function crypto_auth_hmacsha512256_final
!c_memcpy - same as the C function memcpy
type(c_ptr) function c_memcpy(dest, src, n) bind(c,name="memcpy")
use iso_c_binding
type(c_ptr), value, intent(in) :: dest
type(c_ptr), value, intent(in) :: src
integer(c_size_t), value, intent(in) :: n
end function c_memcpy
end interface
end module fortium