Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
cm-projects
RIOT
Commits
68d9f07e
Commit
68d9f07e
authored
8 years ago
by
BytesGalore
Browse files
Options
Downloads
Patches
Plain Diff
hashes/sha1: changed data-parameter types to `void*`
parent
8518843a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/hashes/sha1.c
+13
-11
13 additions, 11 deletions
sys/hashes/sha1.c
sys/include/hashes/sha1.h
+17
-18
17 additions, 18 deletions
sys/include/hashes/sha1.h
with
30 additions
and
29 deletions
sys/hashes/sha1.c
+
13
−
11
View file @
68d9f07e
...
...
@@ -114,10 +114,11 @@ static void sha1_update_byte(sha1_context *ctx, uint8_t data)
sha1_add_uncounted
(
ctx
,
data
);
}
void
sha1_update
(
sha1_context
*
ctx
,
const
uint8_t
*
data
,
size_t
len
)
void
sha1_update
(
sha1_context
*
ctx
,
const
void
*
data
,
size_t
len
)
{
const
uint8_t
*
d
=
data
;
while
(
len
--
)
{
sha1_update_byte
(
ctx
,
*
(
d
ata
++
));
sha1_update_byte
(
ctx
,
*
(
d
++
));
}
}
...
...
@@ -142,7 +143,7 @@ static void sha1_pad(sha1_context *s)
sha1_add_uncounted
(
s
,
s
->
byte_count
<<
3
);
}
void
sha1_final
(
sha1_context
*
ctx
,
uint8_t
*
d
st
)
void
sha1_final
(
sha1_context
*
ctx
,
void
*
dige
st
)
{
/* Pad to complete the last block */
sha1_pad
(
ctx
);
...
...
@@ -157,31 +158,32 @@ void sha1_final(sha1_context *ctx, uint8_t *dst)
}
/* Copy the content of the hash (20 characters) */
memcpy
(
dst
,
ctx
->
state
,
20
);
memcpy
(
d
ige
st
,
ctx
->
state
,
20
);
}
void
sha1
(
uint8_t
*
dst
,
const
uint8_t
*
src
,
size_t
len
)
void
sha1
(
void
*
digest
,
const
void
*
data
,
size_t
len
)
{
sha1_context
ctx
;
sha1_init
(
&
ctx
);
sha1_update
(
&
ctx
,
(
unsigned
char
*
)
src
,
len
);
sha1_final
(
&
ctx
,
dst
);
sha1_update
(
&
ctx
,
(
unsigned
char
*
)
data
,
len
);
sha1_final
(
&
ctx
,
d
ige
st
);
}
#define HMAC_IPAD 0x36
#define HMAC_OPAD 0x5c
void
sha1_init_hmac
(
sha1_context
*
ctx
,
const
uint8_t
*
key
,
size_t
key_length
)
void
sha1_init_hmac
(
sha1_context
*
ctx
,
const
void
*
key
,
size_t
key_length
)
{
uint8_t
i
;
const
uint8_t
*
k
=
key
;
memset
(
ctx
->
key_buffer
,
0
,
SHA1_BLOCK_LENGTH
);
if
(
key_length
>
SHA1_BLOCK_LENGTH
)
{
/* Hash long keys */
sha1_init
(
ctx
);
while
(
key_length
--
)
{
sha1_update_byte
(
ctx
,
*
k
ey
++
);
sha1_update_byte
(
ctx
,
*
k
++
);
}
sha1_final
(
ctx
,
ctx
->
key_buffer
);
}
...
...
@@ -196,7 +198,7 @@ void sha1_init_hmac(sha1_context *ctx, const uint8_t *key, size_t key_length)
}
}
void
sha1_final_hmac
(
sha1_context
*
ctx
,
uint8_t
*
d
st
)
void
sha1_final_hmac
(
sha1_context
*
ctx
,
void
*
dige
st
)
{
uint8_t
i
;
...
...
@@ -211,5 +213,5 @@ void sha1_final_hmac(sha1_context *ctx, uint8_t *dst)
sha1_update_byte
(
ctx
,
ctx
->
inner_hash
[
i
]);
}
sha1_final
(
ctx
,
dst
);
sha1_final
(
ctx
,
d
ige
st
);
}
This diff is collapsed.
Click to expand it.
sys/include/hashes/sha1.h
+
17
−
18
View file @
68d9f07e
...
...
@@ -73,47 +73,46 @@ void sha1_init(sha1_context *ctx);
/**
* @brief Update the SHA-1 context with a portion of the message being hashed
*
* @param[in] ctx
Pointer to the SHA-1 context to update
* @param[in] data
Input data
* @param[in] len
Length of @p data
* @param[in] ctx Pointer to the SHA-1 context to update
* @param[in] data Input data
* @param[in] len Length of @p data
*/
void
sha1_update
(
sha1_context
*
ctx
,
const
uint8_t
*
data
,
size_t
len
);
void
sha1_update
(
sha1_context
*
ctx
,
const
void
*
data
,
size_t
len
);
/**
* @brief Finalizes the SHA-1 message digest
*
* @param[in] ctx Pointer to the SHA-1 context
* @param[out] d
st
Result location, must be 20 byte
* @param[out] d
igest
Result location, must be 20 byte
*
*/
void
sha1_final
(
sha1_context
*
ctx
,
uint8_t
*
d
st
);
void
sha1_final
(
sha1_context
*
ctx
,
void
*
dige
st
);
/**
* @brief Calculate a SHA1 hash from the given data
*
* @param[out] d
st
Result location, must be 20 byte
* @param[in]
src
Input data
* @param[in] len
Length of @p buf
* @param[out] d
igest
Result location, must be 20 byte
* @param[in]
data
Input data
* @param[in] len Length of @p buf
*/
void
sha1
(
uint8_t
*
dst
,
const
uint8_t
*
src
,
size_t
len
);
void
sha1
(
void
*
digest
,
const
void
*
data
,
size_t
len
);
/**
* @brief Initialize SHA-1 message digest context with MAC
*
* @param[in] ctx
Pointer to the SHA-1 context to initialize
* @param[in] key
Key used in the HMAC-SHA1 computation
* @param[in] key_length
The size in bytes of @p key
* @param[in] ctx Pointer to the SHA-1 context to initialize
* @param[in] key Key used in the HMAC-SHA1 computation
* @param[in] key_length The size in bytes of @p key
*/
void
sha1_init_hmac
(
sha1_context
*
ctx
,
const
uint8_t
*
key
,
size_t
key_length
);
void
sha1_init_hmac
(
sha1_context
*
ctx
,
const
void
*
key
,
size_t
key_length
);
/**
* @brief Finalizes the SHA-1 message digest with MAC
*
* @param[in] s Pointer to the SHA-1 context
* @param[out] dst Result location, must be 20 byte
* @return Calculated digest
* @param[in] ctx Pointer to the SHA-1 context
* @param[out] digest Result location, must be 20 byte
*/
void
sha1_final_hmac
(
sha1_context
*
ctx
,
uint8_t
*
d
st
);
void
sha1_final_hmac
(
sha1_context
*
ctx
,
void
*
dige
st
);
#ifdef __cplusplus
}
...
...
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