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
92a64fd5
Commit
92a64fd5
authored
Sep 20, 2017
by
filatov
Browse files
fix BN serialization padding (thanks Michal Kazmierowski)
parent
e5925bfe
Changes
1
Hide whitespace changes
Inline
Side-by-side
tools/itscertgen/generator/ecc_openssl.c
View file @
92a64fd5
...
...
@@ -19,6 +19,8 @@
#include
<openssl/ecdsa.h>
#include
<string.h>
#define FIELD_SIZE 32
#define ARRAYSIZE(A) (sizeof(A)/sizeof(A[0]))
static
char
*
_bin2hex
(
char
*
hex
,
int
hlen
,
const
char
*
bin
,
int
blen
);
...
...
@@ -172,23 +174,25 @@ int ecc_api_key_public(void* key, char * px, char * py)
BIGNUM
x
,
y
;
int
bcount
=
-
1
;
ecgroup
=
EC_KEY_get0_group
(
eckey
);
ecpoint
=
EC_KEY_get0_public_key
(
eckey
);
if
(
key
&&
px
&&
py
)
{
ecgroup
=
EC_KEY_get0_group
(
eckey
);
ecpoint
=
EC_KEY_get0_public_key
(
eckey
);
//fill public key data
BN_init
(
&
x
);
BN_init
(
&
y
);
if
(
EC_POINT_get_affine_coordinates_GFp
(
ecgroup
,
ecpoint
,
&
x
,
&
y
,
NULL
)){
bcount
=
BN_num_bytes
(
&
x
);
if
(
px
){
//fill public key data
BN_init
(
&
x
);
BN_init
(
&
y
);
if
(
EC_POINT_get_affine_coordinates_GFp
(
ecgroup
,
ecpoint
,
&
x
,
&
y
,
NULL
)){
bcount
=
BN_num_bytes
(
&
x
);
for
(;
bcount
<
FIELD_SIZE
;
bcount
++
)
*
(
px
++
)
=
0
;
// add padding with zeros
BN_bn2bin
(
&
x
,
(
unsigned
char
*
)
px
);
}
bcount
=
BN_num_bytes
(
&
y
);
if
(
py
){
bcount
=
BN_num_bytes
(
&
y
);
for
(;
bcount
<
FIELD_SIZE
;
bcount
++
)
*
(
py
++
)
=
0
;
// add padding with zeros
BN_bn2bin
(
&
y
,
(
unsigned
char
*
)
py
);
}
BN_clear_free
(
&
x
);
BN_clear_free
(
&
y
);
}
BN_clear_free
(
&
x
);
BN_clear_free
(
&
y
);
return
bcount
;
}
...
...
@@ -446,12 +450,16 @@ int ecc_sign(void * key, const char * data, int length, char ** psig, int max
ecdsa
=
ECDSA_do_sign
(
hash
,
32
,
eckey
);
EC_KEY_free
(
eckey
);
if
(
ecdsa
){
int
bcount
;
int
i
,
bcount
;
*
(
sig
++
)
=
0
;
// ECC_POINT type (x_coordinate_only)
bcount
=
BN_num_bytes
(
ecdsa
->
r
);
for
(
i
=
bcount
;
i
<
FIELD_SIZE
;
i
++
)
*
(
sig
++
)
=
0
;
// add padding with zeros
BN_bn2bin
(
ecdsa
->
r
,
sig
);
sig
+=
bcount
;
bcount
=
BN_num_bytes
(
ecdsa
->
s
);
for
(
i
=
bcount
;
i
<
FIELD_SIZE
;
i
++
)
*
(
sig
++
)
=
0
;
// add padding with zeros
BN_bn2bin
(
ecdsa
->
s
,
sig
);
sig
+=
bcount
;
ECDSA_SIG_free
(
ecdsa
);
...
...
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