Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lwc
/
compare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ed417d58
authored
Jul 09, 2019
by
Enrico Pozzobon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better input validation in linux template
parent
29172747
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
17 deletions
+35
-17
templates/linux/main.c
+35
-17
No files found.
templates/linux/main.c
View file @
ed417d58
...
...
@@ -111,10 +111,8 @@ int main() {
case
'e'
:
if
(
k
==
NULL
||
c
==
NULL
)
{
fprintf
(
stderr
,
c
==
NULL
?
"Missing ciphertext buffer
\r\n
"
:
"Missing key
\r\n
"
);
return
3
;
}
case
'd'
:
/*
fprintf(stderr, "mlen = %llu\r\n", mlen);
fprintf(stderr, "m = "); FPRINTF_HEX(stderr, m, mlen); fprintf(stderr, "\r\n");
fprintf(stderr, "adlen = %llu\r\n", adlen);
...
...
@@ -125,22 +123,42 @@ int main() {
fprintf(stderr, "ns = "); FPRINTF_HEX(stderr, nsec, nslen); fprintf(stderr, "\r\n");
fprintf(stderr, "klen = %llu\r\n", klen);
fprintf(stderr, "k = "); FPRINTF_HEX(stderr, k, klen); fprintf(stderr, "\r\n");
*/
if
(
k
==
NULL
)
{
fprintf
(
stderr
,
"Missing key
\r\n
"
);
return
3
;
}
fprintf
(
stderr
,
"Starting encryption
\r\n
"
);
res
=
crypto_aead_encrypt
(
c
,
&
clen
,
m
,
mlen
,
ad
,
adlen
,
nsec
,
npub
,
k
);
fprintf
(
stderr
,
"encryption finished %d
\r\n
"
,
res
);
break
;
case
'd'
:
if
(
m
==
NULL
||
k
==
NULL
)
{
fprintf
(
stderr
,
m
==
NULL
?
"Missing message buffer
\r\n
"
:
"Missing key
\r\n
"
);
if
(
npub
==
NULL
)
{
fprintf
(
stderr
,
"Missing nonce
\r\n
"
);
return
3
;
}
fprintf
(
stderr
,
"starting decryption
\r\n
"
);
res
=
crypto_aead_decrypt
(
m
,
&
mlen
,
nsec
,
c
,
clen
,
ad
,
adlen
,
npub
,
k
);
fprintf
(
stderr
,
"decryption finished %d
\r\n
"
,
res
);
if
(
action
==
'e'
)
{
if
(
c
==
NULL
)
{
fprintf
(
stderr
,
"Missing ciphertext buffer
\r\n
"
);
return
3
;
}
fprintf
(
stderr
,
"Starting encryption
\r\n
"
);
res
=
crypto_aead_encrypt
(
c
,
&
clen
,
m
,
mlen
,
ad
,
adlen
,
nsec
,
npub
,
k
);
fprintf
(
stderr
,
"encryption finished %d
\r\n
"
,
res
);
}
else
if
(
action
==
'd'
)
{
if
(
m
==
NULL
)
{
fprintf
(
stderr
,
"Missing message buffer
\r\n
"
);
return
3
;
}
fprintf
(
stderr
,
"starting decryption
\r\n
"
);
res
=
crypto_aead_decrypt
(
m
,
&
mlen
,
nsec
,
c
,
clen
,
ad
,
adlen
,
npub
,
k
);
fprintf
(
stderr
,
"decryption finished %d
\r\n
"
,
res
);
}
break
;
default:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment