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
344b7b67
Commit
344b7b67
authored
Jan 19, 2014
by
Olivier Crête
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stun: Make the MD5 code strict-aliasing correct
parent
4b588f11
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
16 deletions
+19
-16
stun/md5.c
stun/md5.c
+15
-15
stun/md5.h
stun/md5.h
+4
-1
No files found.
stun/md5.c
View file @
344b7b67
...
@@ -92,7 +92,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
...
@@ -92,7 +92,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
/* Handle any leading odd-sized chunks */
/* Handle any leading odd-sized chunks */
if
(
t
)
{
if
(
t
)
{
unsigned
char
*
p
=
(
unsigned
char
*
)
ctx
->
in
+
t
;
unsigned
char
*
p
=
(
unsigned
char
*
)
ctx
->
in
.
u8
+
t
;
t
=
64
-
t
;
t
=
64
-
t
;
if
(
len
<
t
)
{
if
(
len
<
t
)
{
...
@@ -100,24 +100,24 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
...
@@ -100,24 +100,24 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
return
;
return
;
}
}
memcpy
(
p
,
buf
,
t
);
memcpy
(
p
,
buf
,
t
);
byteReverse
(
ctx
->
in
,
16
);
byteReverse
(
ctx
->
in
.
u8
,
16
);
MD5Transform
(
ctx
->
buf
,
(
uint32_t
*
)
ctx
->
in
);
MD5Transform
(
ctx
->
buf
,
ctx
->
in
.
u32
);
buf
+=
t
;
buf
+=
t
;
len
-=
t
;
len
-=
t
;
}
}
/* Process data in 64-byte chunks */
/* Process data in 64-byte chunks */
while
(
len
>=
64
)
{
while
(
len
>=
64
)
{
memcpy
(
ctx
->
in
,
buf
,
64
);
memcpy
(
ctx
->
in
.
u8
,
buf
,
64
);
byteReverse
(
ctx
->
in
,
16
);
byteReverse
(
ctx
->
in
.
u8
,
16
);
MD5Transform
(
ctx
->
buf
,
(
uint32_t
*
)
ctx
->
in
);
MD5Transform
(
ctx
->
buf
,
ctx
->
in
.
u32
);
buf
+=
64
;
buf
+=
64
;
len
-=
64
;
len
-=
64
;
}
}
/* Handle any remaining bytes of data. */
/* Handle any remaining bytes of data. */
memcpy
(
ctx
->
in
,
buf
,
len
);
memcpy
(
ctx
->
in
.
u8
,
buf
,
len
);
}
}
/*
/*
...
@@ -134,7 +134,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
...
@@ -134,7 +134,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
/* Set the first char of padding to 0x80. This is safe since there is
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
always at least one byte free */
p
=
ctx
->
in
+
count
;
p
=
ctx
->
in
.
u8
+
count
;
*
p
++
=
0x80
;
*
p
++
=
0x80
;
/* Bytes of padding needed to make 64 bytes */
/* Bytes of padding needed to make 64 bytes */
...
@@ -144,22 +144,22 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
...
@@ -144,22 +144,22 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
if
(
count
<
8
)
{
if
(
count
<
8
)
{
/* Two lots of padding: Pad the first block to 64 bytes */
/* Two lots of padding: Pad the first block to 64 bytes */
memset
(
p
,
0
,
count
);
memset
(
p
,
0
,
count
);
byteReverse
(
ctx
->
in
,
16
);
byteReverse
(
ctx
->
in
.
u8
,
16
);
MD5Transform
(
ctx
->
buf
,
(
uint32_t
*
)
ctx
->
in
);
MD5Transform
(
ctx
->
buf
,
ctx
->
in
.
u32
);
/* Now fill the next block with 56 bytes */
/* Now fill the next block with 56 bytes */
memset
(
ctx
->
in
,
0
,
56
);
memset
(
ctx
->
in
.
u8
,
0
,
56
);
}
else
{
}
else
{
/* Pad block to 56 bytes */
/* Pad block to 56 bytes */
memset
(
p
,
0
,
count
-
8
);
memset
(
p
,
0
,
count
-
8
);
}
}
byteReverse
(
ctx
->
in
,
14
);
byteReverse
(
ctx
->
in
.
u8
,
14
);
/* Append length in bits and transform */
/* Append length in bits and transform */
((
uint32_t
*
)
ctx
->
in
)
[
14
]
=
ctx
->
bits
[
0
];
ctx
->
in
.
u32
[
14
]
=
ctx
->
bits
[
0
];
((
uint32_t
*
)
ctx
->
in
)
[
15
]
=
ctx
->
bits
[
1
];
ctx
->
in
.
u32
[
15
]
=
ctx
->
bits
[
1
];
MD5Transform
(
ctx
->
buf
,
(
uint32_t
*
)
ctx
->
in
);
MD5Transform
(
ctx
->
buf
,
ctx
->
in
.
u32
);
byteReverse
((
unsigned
char
*
)
ctx
->
buf
,
4
);
byteReverse
((
unsigned
char
*
)
ctx
->
buf
,
4
);
memcpy
(
digest
,
ctx
->
buf
,
16
);
memcpy
(
digest
,
ctx
->
buf
,
16
);
memset
(
ctx
,
0
,
sizeof
(
struct
MD5Context
));
/* In case it's sensitive */
memset
(
ctx
,
0
,
sizeof
(
struct
MD5Context
));
/* In case it's sensitive */
...
...
stun/md5.h
View file @
344b7b67
...
@@ -27,7 +27,10 @@
...
@@ -27,7 +27,10 @@
struct
MD5Context
{
struct
MD5Context
{
uint32_t
buf
[
4
];
uint32_t
buf
[
4
];
uint32_t
bits
[
2
];
uint32_t
bits
[
2
];
uint8_t
in
[
64
];
union
{
uint8_t
u8
[
64
];
uint32_t
u32
[
16
];
}
in
;
};
};
typedef
struct
MD5Context
MD5_CTX
;
typedef
struct
MD5Context
MD5_CTX
;
...
...
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