Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
ae663163
Commit
ae663163
authored
Mar 21, 2011
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some new APIs to sha1 module, unused for now
parent
dd53998e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
9 deletions
+75
-9
stun/sha1.c
stun/sha1.c
+61
-1
stun/sha1.h
stun/sha1.h
+14
-8
No files found.
stun/sha1.c
View file @
ae663163
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
*/
*/
#include "sha1.h"
#include "sha1.h"
#include <string.h>
#include <string.h>
/* ===== start - public domain SHA1 implementation ===== */
/* ===== start - public domain SHA1 implementation ===== */
...
@@ -262,6 +262,66 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
...
@@ -262,6 +262,66 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
/* ===== end - public domain SHA1 implementation ===== */
/* ===== end - public domain SHA1 implementation ===== */
void
HMACInit
(
HMAC_CTX
*
context
,
const
uint8_t
*
key
,
size_t
key_len
)
{
unsigned
char
ipad
[
64
];
/* padding - key XORd with ipad */
unsigned
char
tk
[
20
];
size_t
i
;
/* if key is longer than 64 bytes reset it to key = SHA1(key) */
if
(
key_len
>
64
)
{
sha1_vector
(
1
,
&
key
,
&
key_len
,
tk
);
key
=
tk
;
key_len
=
20
;
}
/* start out by storing key in ipad */
memset
(
ipad
,
0
,
sizeof
(
ipad
));
memcpy
(
ipad
,
key
,
key_len
);
/* XOR key with ipad values */
for
(
i
=
0
;
i
<
64
;
i
++
)
ipad
[
i
]
^=
0x36
;
/* Store the key in our context */
memcpy
(
context
->
key
,
key
,
key_len
);
context
->
key_len
=
key_len
;
SHA1Init
(
&
context
->
context
);
SHA1Update
(
&
context
->
context
,
ipad
,
sizeof
(
ipad
));
}
void
HMACUpdate
(
HMAC_CTX
*
context
,
const
void
*
data
,
uint32_t
len
)
{
SHA1Update
(
&
context
->
context
,
data
,
len
);
}
void
HMACFinal
(
unsigned
char
digest
[
20
],
HMAC_CTX
*
context
)
{
unsigned
char
opad
[
64
];
/* padding - key XORd with opad */
unsigned
char
sha1_digest
[
SHA1_MAC_LEN
];
const
uint8_t
*
_addr
[
2
];
size_t
_len
[
2
];
size_t
i
;
SHA1Final
(
sha1_digest
,
&
context
->
context
);
memset
(
opad
,
0
,
sizeof
(
opad
));
memcpy
(
opad
,
context
->
key
,
context
->
key_len
);
/* XOR key with opad values */
for
(
i
=
0
;
i
<
64
;
i
++
)
opad
[
i
]
^=
0x5c
;
/* perform outer SHA1 */
_addr
[
0
]
=
opad
;
_len
[
0
]
=
64
;
_addr
[
1
]
=
sha1_digest
;
_len
[
1
]
=
SHA1_MAC_LEN
;
sha1_vector
(
2
,
_addr
,
_len
,
digest
);
}
/**
/**
* hmac_sha1_vector:
* hmac_sha1_vector:
...
...
stun/sha1.h
View file @
ae663163
...
@@ -15,16 +15,11 @@
...
@@ -15,16 +15,11 @@
#ifndef SHA1_H
#ifndef SHA1_H
#define SHA1_H
#define SHA1_H
#ifdef _WIN32
#include "win32_common.h"
#else
#include <stdint.h>
#include <stdint.h>
#endif
#include <stddef.h>
#include <stddef.h>
#define SHA1_MAC_LEN 20
#define SHA1_MAC_LEN 20
struct
SHA1Context
{
struct
SHA1Context
{
uint32_t
state
[
5
];
uint32_t
state
[
5
];
uint32_t
count
[
2
];
uint32_t
count
[
2
];
...
@@ -37,6 +32,17 @@ void SHA1Init(SHA1_CTX *context);
...
@@ -37,6 +32,17 @@ void SHA1Init(SHA1_CTX *context);
void
SHA1Update
(
SHA1_CTX
*
context
,
const
void
*
data
,
uint32_t
len
);
void
SHA1Update
(
SHA1_CTX
*
context
,
const
void
*
data
,
uint32_t
len
);
void
SHA1Final
(
unsigned
char
digest
[
20
],
SHA1_CTX
*
context
);
void
SHA1Final
(
unsigned
char
digest
[
20
],
SHA1_CTX
*
context
);
struct
HMACContext
{
SHA1_CTX
context
;
uint8_t
key
[
64
];
size_t
key_len
;
};
typedef
struct
HMACContext
HMAC_CTX
;
void
HMACInit
(
HMAC_CTX
*
context
,
const
uint8_t
*
key
,
size_t
key_len
);
void
HMACUpdate
(
HMAC_CTX
*
context
,
const
void
*
data
,
uint32_t
len
);
void
HMACFinal
(
unsigned
char
digest
[
20
],
HMAC_CTX
*
context
);
void
sha1_vector
(
size_t
num_elem
,
const
uint8_t
*
addr
[],
const
size_t
*
len
,
void
sha1_vector
(
size_t
num_elem
,
const
uint8_t
*
addr
[],
const
size_t
*
len
,
uint8_t
*
mac
);
uint8_t
*
mac
);
void
hmac_sha1_vector
(
const
uint8_t
*
key
,
size_t
key_len
,
size_t
num_elem
,
void
hmac_sha1_vector
(
const
uint8_t
*
key
,
size_t
key_len
,
size_t
num_elem
,
...
...
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