Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cellframe-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
20
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cellframe
cellframe-sdk
Commits
61e4df79
Commit
61e4df79
authored
4 years ago
by
Dmitriy A. Gerasimov
Browse files
Options
Downloads
Patches
Plain Diff
[!] Dirty hack for old-serialized keys and signatures
parent
151263eb
No related branches found
No related tags found
No related merge requests found
Pipeline
#6969
passed with stage
in 11 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+1
-1
1 addition, 1 deletion
CMakeLists.txt
dap-sdk/crypto/include/dap_enc_dilithium.h
+2
-0
2 additions, 0 deletions
dap-sdk/crypto/include/dap_enc_dilithium.h
dap-sdk/crypto/src/dap_enc_dilithium.c
+30
-8
30 additions, 8 deletions
dap-sdk/crypto/src/dap_enc_dilithium.c
with
33 additions
and
9 deletions
CMakeLists.txt
+
1
−
1
View file @
61e4df79
...
...
@@ -2,7 +2,7 @@ project(cellframe-sdk C)
cmake_minimum_required
(
VERSION 2.8
)
set
(
CMAKE_C_STANDARD 11
)
set
(
CELLFRAME_SDK_NATIVE_VERSION
"2.6-10
4
"
)
set
(
CELLFRAME_SDK_NATIVE_VERSION
"2.6-10
5
"
)
add_definitions
(
"-DCELLFRAME_SDK_VERSION=
\"
${
CELLFRAME_SDK_NATIVE_VERSION
}
\"
"
)
set
(
DAPSDK_MODULES
""
)
...
...
This diff is collapsed.
Click to expand it.
dap-sdk/crypto/include/dap_enc_dilithium.h
+
2
−
0
View file @
61e4df79
...
...
@@ -34,6 +34,8 @@ static inline size_t dap_enc_dilithium_calc_signagture_size(dilithium_signature_
uint8_t
*
dap_enc_dilithium_write_signature
(
dilithium_signature_t
*
a_sign
,
size_t
*
a_sign_out
);
dilithium_signature_t
*
dap_enc_dilithium_read_signature
(
uint8_t
*
a_buf
,
size_t
a_buflen
);
dilithium_signature_t
*
dap_enc_dilithium_read_signature_old
(
uint8_t
*
a_buf
,
size_t
a_buflen
);
uint8_t
*
dap_enc_dilithium_write_private_key
(
const
dilithium_private_key_t
*
a_private_key
,
size_t
*
a_buflen_out
);
uint8_t
*
dap_enc_dilithium_write_public_key
(
const
dilithium_public_key_t
*
a_public_key
,
size_t
*
a_buflen_out
);
dilithium_private_key_t
*
dap_enc_dilithium_read_private_key
(
const
uint8_t
*
a_buf
,
size_t
a_buflen
);
...
...
This diff is collapsed.
Click to expand it.
dap-sdk/crypto/src/dap_enc_dilithium.c
+
30
−
8
View file @
61e4df79
...
...
@@ -157,10 +157,13 @@ dilithium_signature_t* dap_enc_dilithium_read_signature(uint8_t *a_buf, size_t a
return
NULL
;
}
uint64_t
l_shift_mem
=
0
;
dilithium_kind_t
kind
;
uint64_t
l_buflen_internal
=
0
;
memcpy
(
&
l_buflen_internal
,
a_buf
,
sizeof
(
uint64_t
));
memcpy
(
&
kind
,
a_buf
+
sizeof
(
uint64_t
),
sizeof
(
dilithium_kind_t
));
l_shift_mem
+=
sizeof
(
uint64_t
);
memcpy
(
&
kind
,
a_buf
+
l_shift_mem
,
sizeof
(
dilithium_kind_t
));
l_shift_mem
+=
sizeof
(
dilithium_kind_t
);
if
(
l_buflen_internal
!=
a_buflen
)
return
NULL
;
dilithium_param_t
p
;
...
...
@@ -169,22 +172,30 @@ dilithium_signature_t* dap_enc_dilithium_read_signature(uint8_t *a_buf, size_t a
dilithium_signature_t
*
l_sign
=
DAP_NEW
(
dilithium_signature_t
);
l_sign
->
kind
=
kind
;
uint64_t
l_shift_mem
=
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
);
memcpy
(
&
l_sign
->
sig_len
,
a_buf
+
l_shift_mem
,
sizeof
(
uint64_t
));
l_shift_mem
+=
sizeof
(
uint64_t
);
if
(
l_sign
->
sig_len
>
(
UINT64_MAX
-
l_shift_mem
)
){
log_it
(
L_ERROR
,
"::read_signature() Buflen inside signature %zd is too big "
,
l_sign
->
sig_len
);
return
NULL
;
}
// Dirty hack for old 32 bit version serializations
if
(
l_sign
->
sig_len
+
l_shift_mem
+
8
==
a_buflen
){
return
dap_enc_dilithium_read_signature_old
(
a_buf
,
a_buflen
);
}
if
(
(
l_sign
->
sig_len
>
(
UINT64_MAX
-
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
)
+
sizeof
(
uint64_t
)))
||
(
a_buflen
<
(
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
)
+
sizeof
(
uint64_t
)
+
l_sign
->
sig_len
))
){
if
(
a_buflen
<
(
l_shift_mem
+
l_sign
->
sig_len
)
){
log_it
(
L_ERROR
,
"::read_signature() Buflen %zd is smaller than all fields together(%zd)"
,
a_buflen
,
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
)
+
l_sign
->
sig_len
);
l_shift_mem
+
l_sign
->
sig_len
);
return
NULL
;
}
l_shift_mem
+=
l_sign
->
sig_len
;
l_shift_mem
+=
sizeof
(
uint64_t
);
l_sign
->
sig_data
=
DAP_NEW_SIZE
(
unsigned
char
,
l_sign
->
sig_len
);
if
(
!
l_sign
->
sig_data
)
log_it
(
L_ERROR
,
"::read_signature() Can't allocate sig_data %zd size"
,
l_sign
->
sig_len
);
memcpy
(
l_sign
->
sig_data
,
a_buf
+
l_shift_mem
,
l_sign
->
sig_len
);
l_shift_mem
+=
l_sign
->
sig_len
;
return
l_sign
;
...
...
@@ -263,6 +274,11 @@ dilithium_private_key_t* dap_enc_dilithium_read_private_key(const uint8_t *a_buf
return
NULL
;
}
// Dirty hack to recognize old variant
if
(
a_buflen
+
8
==
(
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
))){
return
dap_enc_dilithium_read_private_key_old
(
a_buf
,
a_buflen
);
}
if
(
a_buflen
<
(
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
))){
log_it
(
L_ERROR
,
"::read_private_key() Buflen %zd is smaller than first two fields(%zd)"
,
a_buflen
,
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
)
);
return
NULL
;
...
...
@@ -331,6 +347,7 @@ dilithium_public_key_t* dap_enc_dilithium_read_public_key(const uint8_t *a_buf,
log_it
(
L_ERROR
,
"::read_public_key() Buflen %zd is smaller than first two fields(%zd)"
,
a_buflen
,
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
)
);
return
NULL
;
}
dilithium_kind_t
kind
=
0
;
uint64_t
l_buflen
=
0
;
memcpy
(
&
l_buflen
,
a_buf
,
sizeof
(
uint64_t
));
...
...
@@ -345,6 +362,11 @@ dilithium_public_key_t* dap_enc_dilithium_read_public_key(const uint8_t *a_buf,
return
NULL
;
}
// Dirty hack to recognize old variant
if
(
a_buflen
+
8
==
(
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
)
+
p
.
CRYPTO_PUBLICKEYBYTES
)){
return
dap_enc_dilithium_read_public_key_old
(
a_buf
,
a_buflen
);
}
if
(
a_buflen
<
(
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
)
+
p
.
CRYPTO_PUBLICKEYBYTES
)
){
log_it
(
L_ERROR
,
"::read_public_key() Buflen %zd is smaller than all fields together(%zd)"
,
a_buflen
,
sizeof
(
uint64_t
)
+
sizeof
(
dilithium_kind_t
)
+
p
.
CRYPTO_PUBLICKEYBYTES
);
...
...
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