Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
enacl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
talla
enacl
Commits
772a97d3
Commit
772a97d3
authored
Nov 24, 2014
by
Jesper Louis Andersen
Browse files
Options
Downloads
Patches
Plain Diff
Implement low level code for the authenticators.
parent
101c16e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
c_src/enacl_nif.c
+59
-0
59 additions, 0 deletions
c_src/enacl_nif.c
with
59 additions
and
0 deletions
c_src/enacl_nif.c
+
59
−
0
View file @
772a97d3
...
...
@@ -177,6 +177,11 @@ ERL_NIF_TERM enif_crypto_stream_NONCEBYTES(ErlNifEnv *env, int argc, ERL_NIF_TER
return
enif_make_int64
(
env
,
crypto_stream_NONCEBYTES
);
}
static
ERL_NIF_TERM
enif_crypto_auth_KEYBYTES
(
ErlNifEnv
*
env
,
int
argc
,
ERL_NIF_TERM
const
argv
[])
{
return
enif_make_int64
(
env
,
crypto_auth_KEYBYTES
);
}
static
ERL_NIF_TERM
enif_crypto_secretbox
(
ErlNifEnv
*
env
,
int
argc
,
ERL_NIF_TERM
const
argv
[])
{
ErlNifBinary
key
,
nonce
,
padded_msg
,
padded_ciphertext
;
...
...
@@ -307,6 +312,56 @@ ERL_NIF_TERM enif_crypto_stream_xor(ErlNifEnv *env, int argc, ERL_NIF_TERM const
return
enif_make_binary
(
env
,
&
c
);
}
static
ERL_NIF_TERM
enif_crypto_auth
(
ErlNifEnv
*
env
,
int
argc
,
ERL_NIF_TERM
const
argv
[])
{
ErlNifBinary
a
,
m
,
k
;
if
(
(
argc
!=
2
)
||
(
!
enif_inspect_iolist_as_binary
(
env
,
argv
[
0
],
&
m
))
||
(
!
enif_inspect_iolist_as_binary
(
env
,
argv
[
1
],
&
k
)))
{
return
enif_make_badarg
(
env
);
}
if
(
k
.
size
!=
crypto_auth_KEYBYTES
)
{
return
enif_make_badarg
(
env
);
}
if
(
!
enif_alloc_binary
(
crypto_auth_BYTES
,
&
a
))
{
return
nacl_error_tuple
(
env
,
"alloc_failed"
);
}
crypto_auth
(
a
.
data
,
m
.
data
,
m
.
size
,
k
.
data
);
return
enif_make_binary
(
env
,
&
a
);
}
static
ERL_NIF_TERM
enif_crypto_auth_verify
(
ErlNifEnv
*
env
,
int
argc
,
ERL_NIF_TERM
const
argv
[])
{
ErlNifBinary
a
,
m
,
k
;
if
(
(
argc
!=
3
)
||
(
!
enif_inspect_iolist_as_binary
(
env
,
argv
[
0
],
&
a
))
||
(
!
enif_inspect_iolist_as_binary
(
env
,
argv
[
1
],
&
m
))
||
(
!
enif_inspect_iolist_as_binary
(
env
,
argv
[
2
],
&
k
)))
{
return
enif_make_badarg
(
env
);
}
if
(
(
k
.
size
!=
crypto_auth_KEYBYTES
)
||
(
a
.
size
!=
crypto_auth_BYTES
))
{
return
enif_make_badarg
(
env
);
}
if
(
0
==
crypto_auth_verify
(
a
.
data
,
m
.
data
,
m
.
size
,
k
.
data
))
{
return
enif_make_atom
(
env
,
"true"
);
}
else
{
return
enif_make_atom
(
env
,
"false"
);
}
}
/* Tie the knot to the Erlang world */
static
ErlNifFunc
nif_funcs
[]
=
{
{
"crypto_box_NONCEBYTES"
,
0
,
enif_crypto_box_NONCEBYTES
},
...
...
@@ -330,6 +385,10 @@ static ErlNifFunc nif_funcs[] = {
{
"crypto_stream"
,
3
,
enif_crypto_stream
,
ERL_NIF_DIRTY_JOB_CPU_BOUND
},
{
"crypto_stream_xor"
,
3
,
enif_crypto_stream_xor
,
ERL_NIF_DIRTY_JOB_CPU_BOUND
},
{
"crypto_auth_KEYBYTES"
,
0
,
enif_crypto_auth_KEYBYTES
},
{
"crypto_auth"
,
2
,
enif_crypto_auth
,
ERL_NIF_DIRTY_JOB_CPU_BOUND
},
{
"crypto_auth_verify"
,
3
,
enif_crypto_auth_verify
,
ERL_NIF_DIRTY_JOB_CPU_BOUND
},
{
"crypto_hash"
,
1
,
enif_crypto_hash
,
ERL_NIF_DIRTY_JOB_CPU_BOUND
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment