Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ITS - Intelligent Transport Systems
ITS
Commits
d64463e2
Commit
d64463e2
authored
Nov 29, 2018
by
Yann Garcia
Browse files
Bug fixed in UDP layer
parent
d8e084dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
ccsrc/Externals/LibItsSecurity_externals.cc
View file @
d64463e2
...
...
@@ -119,6 +119,39 @@ namespace LibItsSecurity__Functions
return
OCTETSTRING
(
0
,
nullptr
);
}
OCTETSTRING
fx__test__signWithEcdsaNistp256WithSha256
(
const
OCTETSTRING
&
p__toBeSignedSecuredMessage
,
const
OCTETSTRING
&
p__privateKey
)
{
loggers
::
get_instance
().
log_msg
(
">>> fx__test__signWithEcdsaNistp256WithSha256: data="
,
p__toBeSignedSecuredMessage
);
loggers
::
get_instance
().
log_msg
(
">>> fx__test__signWithEcdsaNistp256WithSha256: private key="
,
p__privateKey
);
// Sanity checks
if
(
p__privateKey
.
lengthof
()
!=
32
)
{
loggers
::
get_instance
().
log
(
"fx__test__signWithEcdsaNistp256WithSha256: Wrong parameters"
);
return
OCTETSTRING
(
0
,
nullptr
);
}
// Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) )
sha256
hash
;
OCTETSTRING
hashData1
;
// Hash (Data input)
hash
.
generate
(
p__toBeSignedSecuredMessage
,
hashData1
);
loggers
::
get_instance
().
log_msg
(
"fx__test__signWithEcdsaNistp256WithSha256: Hash (Data input)="
,
hashData1
);
// Calculate the signature
security_ecc
k
(
ec_elliptic_curves
::
nist_p_256
,
p__privateKey
);
OCTETSTRING
r_sig
;
OCTETSTRING
s_sig
;
if
(
k
.
sign
(
hashData1
,
r_sig
,
s_sig
)
==
0
)
{
OCTETSTRING
os
=
r_sig
+
s_sig
;
loggers
::
get_instance
().
log_msg
(
"r_sig= "
,
r_sig
);
loggers
::
get_instance
().
log_msg
(
"s_sig= "
,
s_sig
);
loggers
::
get_instance
().
log_msg
(
"sig= "
,
os
);
return
os
;
}
return
OCTETSTRING
(
0
,
nullptr
);
}
/**
* \fn OCTETSTRING fx__signWithEcdsaBrainpoolp256WithSha256(const OCTETSTRING& p__toBeSignedSecuredMessage, const OCTETSTRING& p__privateKey);
* \brief Produces a Elliptic Curve Digital Signature Algorithm (ECDSA) signature
...
...
@@ -266,6 +299,32 @@ namespace LibItsSecurity__Functions
return
FALSE
;
}
BOOLEAN
fx__test__verifyWithEcdsaNistp256WithSha256
(
const
OCTETSTRING
&
p__toBeVerifiedData
,
const
OCTETSTRING
&
p__signature
,
const
OCTETSTRING
&
p__ecdsaNistp256PublicKeyCompressed
,
const
INTEGER
&
p__compressedMode
)
{
// Sanity checks
if
((
p__signature
.
lengthof
()
!=
64
)
||
(
p__ecdsaNistp256PublicKeyCompressed
.
lengthof
()
!=
32
))
{
loggers
::
get_instance
().
log
(
"fx__test__verifyWithEcdsaNistp256WithSha256: Wrong parameters"
);
return
FALSE
;
}
// Calculate the SHA256 of the hashed data for signing: Hash ( Hash (Data input) || Hash (Signer identifier input) )
sha256
hash
;
OCTETSTRING
hashData1
;
// Hash (Data input)
hash
.
generate
(
p__toBeVerifiedData
,
hashData1
);
loggers
::
get_instance
().
log_msg
(
"fx__test__verifyWithEcdsaNistp256WithSha256: Hash (Data input)="
,
hashData1
);
// Check the signature
security_ecc
k
(
ec_elliptic_curves
::
nist_p_256
,
p__ecdsaNistp256PublicKeyCompressed
,
(
p__compressedMode
==
0
)
?
ecc_compressed_mode
::
compressed_y_0
:
ecc_compressed_mode
::
compressed_y_1
);
if
(
k
.
sign_verif
(
hashData1
,
p__signature
)
==
0
)
{
return
TRUE
;
}
return
FALSE
;
}
/**
* \fn BOOLEAN fx__verifyWithEcdsaNistp256WithSha256_1(const OCTETSTRING& p__toBeVerifiedData, const OCTETSTRING& p__signature, const OCTETSTRING& p__ecdsaNistp256PublicKeyX, const OCTETSTRING& p__ecdsaNistp256PublicKeyY);
* \brief Verify the signature of the specified data
...
...
LibIts
@
31fa685d
Compare
419abe76
...
31fa685d
Subproject commit
419abe762498812e1d5c8eccc7d90a397153be88
Subproject commit
31fa685dc4be0cb5b2f1a751565080e88ce71a97
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment