Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
7867fd08
Commit
7867fd08
authored
Jun 05, 2015
by
Johny Mattsson
Browse files
Move crypto things to irom0.text segment.
This releases 1168 bytes back to the heap.
parent
223a9367
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/crypto/digests.c
View file @
7867fd08
...
...
@@ -55,7 +55,7 @@ typedef char ensure_int_and_size_t_same[(sizeof(int)==sizeof(size_t)) ? 0 : -1];
ds, \
bs }
static
const
digest_mech_info_t
hash_mechs
[]
=
static
const
digest_mech_info_t
hash_mechs
[]
ICACHE_RODATA_ATTR
=
{
#ifdef MD2_ENABLE
MECH
(
MD2
,
_
,
MD2_SIZE
,
16
),
...
...
@@ -71,7 +71,7 @@ static const digest_mech_info_t hash_mechs[] =
#undef MECH
const
digest_mech_info_t
*
crypto_digest_mech
(
const
char
*
mech
)
const
digest_mech_info_t
*
ICACHE_FLASH_ATTR
crypto_digest_mech
(
const
char
*
mech
)
{
if
(
!
mech
)
return
0
;
...
...
@@ -86,28 +86,22 @@ const digest_mech_info_t *crypto_digest_mech (const char *mech)
return
0
;
}
static
const
char
hex
[]
=
"0123456789abcdef"
;
const
char
crypto_hexbytes
[]
=
"0123456789abcdef"
;
// note: supports in-place encoding
void
crypto_encode_asciihex
(
const
char
*
bin
,
size_t
binlen
,
char
*
outbuf
)
void
ICACHE_FLASH_ATTR
crypto_encode_asciihex
(
const
char
*
bin
,
size_t
binlen
,
char
*
outbuf
)
{
size_t
aidx
=
binlen
*
2
-
1
;
int
i
;
for
(
i
=
binlen
-
1
;
i
>=
0
;
--
i
)
{
outbuf
[
aidx
--
]
=
hex
[
bin
[
i
]
&
0xf
];
outbuf
[
aidx
--
]
=
hex
[
bin
[
i
]
>>
4
];
outbuf
[
aidx
--
]
=
crypto_hexbytes
[
bin
[
i
]
&
0xf
];
outbuf
[
aidx
--
]
=
crypto_hexbytes
[
bin
[
i
]
>>
4
];
}
}
size_t
crypto_digest_size
(
const
char
*
mech
)
{
const
digest_mech_info_t
*
mi
=
crypto_digest_mech
(
mech
);
return
mi
?
mi
->
digest_size
:
0
;
}
int
crypto_hash
(
const
digest_mech_info_t
*
mi
,
int
ICACHE_FLASH_ATTR
crypto_hash
(
const
digest_mech_info_t
*
mi
,
const
char
*
data
,
size_t
data_len
,
uint8_t
*
digest
)
{
...
...
@@ -127,7 +121,7 @@ int crypto_hash (const digest_mech_info_t *mi,
}
int
crypto_hmac
(
const
digest_mech_info_t
*
mi
,
int
ICACHE_FLASH_ATTR
crypto_hmac
(
const
digest_mech_info_t
*
mi
,
const
char
*
data
,
size_t
data_len
,
const
char
*
key
,
size_t
key_len
,
uint8_t
*
digest
)
...
...
app/crypto/digests.h
View file @
7867fd08
...
...
@@ -24,13 +24,14 @@ typedef void (*finalize_ctx_fn)(uint8_t *digest, void *ctx);
*/
typedef
struct
{
/* Note: All entries are 32bit to enable placement using ICACHE_RODATA_ATTR.*/
const
char
*
name
;
create_ctx_fn
create
;
update_ctx_fn
update
;
finalize_ctx_fn
finalize
;
uint
16
_t
ctx_size
;
uint
16
_t
digest_size
;
uint
16
_t
block_size
;
uint
32
_t
ctx_size
;
uint
32
_t
digest_size
;
uint
32
_t
block_size
;
}
digest_mech_info_t
;
...
...
@@ -78,4 +79,7 @@ int crypto_hmac (const digest_mech_info_t *mi, const char *data, size_t data_len
void
crypto_encode_asciihex
(
const
char
*
bin
,
size_t
bin_len
,
char
*
outbuf
);
/** Text string "0123456789abcdef" */
const
char
crypto_hexbytes
[
17
];
#endif
app/crypto/sha2.c
View file @
7867fd08
...
...
@@ -172,7 +172,7 @@ void SHA512_Transform(SHA512_CTX*, const sha2_word64*);
/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
/* Hash constant words K for SHA-256: */
const
static
sha2_word32
K256
[
64
]
=
{
const
static
sha2_word32
K256
[
64
]
ICACHE_RODATA_ATTR
=
{
0x428a2f98UL
,
0x71374491UL
,
0xb5c0fbcfUL
,
0xe9b5dba5UL
,
0x3956c25bUL
,
0x59f111f1UL
,
0x923f82a4UL
,
0xab1c5ed5UL
,
0xd807aa98UL
,
0x12835b01UL
,
0x243185beUL
,
0x550c7dc3UL
,
...
...
@@ -192,7 +192,7 @@ const static sha2_word32 K256[64] = {
};
/* Initial hash value H for SHA-256: */
const
static
sha2_word32
sha256_initial_hash_value
[
8
]
=
{
const
static
sha2_word32
sha256_initial_hash_value
[
8
]
ICACHE_RODATA_ATTR
=
{
0x6a09e667UL
,
0xbb67ae85UL
,
0x3c6ef372UL
,
...
...
@@ -204,7 +204,7 @@ const static sha2_word32 sha256_initial_hash_value[8] = {
};
/* Hash constant words K for SHA-384 and SHA-512: */
const
static
sha2_word64
K512
[
80
]
=
{
const
static
sha2_word64
K512
[
80
]
ICACHE_RODATA_ATTR
=
{
0x428a2f98d728ae22ULL
,
0x7137449123ef65cdULL
,
0xb5c0fbcfec4d3b2fULL
,
0xe9b5dba58189dbbcULL
,
0x3956c25bf348b538ULL
,
0x59f111f1b605d019ULL
,
...
...
@@ -248,7 +248,7 @@ const static sha2_word64 K512[80] = {
};
/* Initial hash value H for SHA-384 */
const
static
sha2_word64
sha384_initial_hash_value
[
8
]
=
{
const
static
sha2_word64
sha384_initial_hash_value
[
8
]
ICACHE_RODATA_ATTR
=
{
0xcbbb9d5dc1059ed8ULL
,
0x629a292a367cd507ULL
,
0x9159015a3070dd17ULL
,
...
...
@@ -260,7 +260,7 @@ const static sha2_word64 sha384_initial_hash_value[8] = {
};
/* Initial hash value H for SHA-512 */
const
static
sha2_word64
sha512_initial_hash_value
[
8
]
=
{
const
static
sha2_word64
sha512_initial_hash_value
[
8
]
ICACHE_RODATA_ATTR
=
{
0x6a09e667f3bcc908ULL
,
0xbb67ae8584caa73bULL
,
0x3c6ef372fe94f82bULL
,
...
...
app/modules/crypto.c
View file @
7867fd08
...
...
@@ -65,7 +65,6 @@ static int crypto_base64_encode( lua_State* L )
return
1
;
}
static
const
char
*
byteshex
=
"0123456789abcdef"
;
/**
* encoded = crypto.toHex(raw)
*
...
...
@@ -78,8 +77,8 @@ static int crypto_hex_encode( lua_State* L)
char
*
out
=
(
char
*
)
c_malloc
(
len
*
2
);
int
i
,
j
=
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
out
[
j
++
]
=
bytes
hex
[
msg
[
i
]
>>
4
];
out
[
j
++
]
=
bytes
hex
[
msg
[
i
]
&
0xf
];
out
[
j
++
]
=
crypto_hex
bytes
[
msg
[
i
]
>>
4
];
out
[
j
++
]
=
crypto_hex
bytes
[
msg
[
i
]
&
0xf
];
}
lua_pushlstring
(
L
,
out
,
len
*
2
);
c_free
(
out
);
...
...
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