Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
3ff56dae
Commit
3ff56dae
authored
Nov 21, 2020
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hash: use GIT_ASSERT
parent
cac36006
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
22 deletions
+25
-22
src/hash/sha1/collisiondetect.c
+3
-3
src/hash/sha1/common_crypto.c
+3
-3
src/hash/sha1/mbedtls.c
+4
-4
src/hash/sha1/openssl.c
+3
-3
src/hash/sha1/win32.c
+12
-9
No files found.
src/hash/sha1/collisiondetect.c
View file @
3ff56dae
...
...
@@ -24,21 +24,21 @@ void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
int
git_hash_sha1_init
(
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
SHA1DCInit
(
&
ctx
->
c
);
return
0
;
}
int
git_hash_sha1_update
(
git_hash_sha1_ctx
*
ctx
,
const
void
*
data
,
size_t
len
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
SHA1DCUpdate
(
&
ctx
->
c
,
data
,
len
);
return
0
;
}
int
git_hash_sha1_final
(
git_oid
*
out
,
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
if
(
SHA1DCFinal
(
out
->
id
,
&
ctx
->
c
))
{
git_error_set
(
GIT_ERROR_SHA1
,
"SHA1 collision attack detected"
);
return
-
1
;
...
...
src/hash/sha1/common_crypto.c
View file @
3ff56dae
...
...
@@ -26,7 +26,7 @@ void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
int
git_hash_sha1_init
(
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
CC_SHA1_Init
(
&
ctx
->
c
);
return
0
;
}
...
...
@@ -35,7 +35,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len)
{
const
unsigned
char
*
data
=
_data
;
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
while
(
len
>
0
)
{
CC_LONG
chunk
=
(
len
>
CC_LONG_MAX
)
?
CC_LONG_MAX
:
(
CC_LONG
)
len
;
...
...
@@ -51,7 +51,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *_data, size_t len)
int
git_hash_sha1_final
(
git_oid
*
out
,
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
CC_SHA1_Final
(
out
->
id
,
&
ctx
->
c
);
return
0
;
}
src/hash/sha1/mbedtls.c
View file @
3ff56dae
...
...
@@ -19,13 +19,13 @@ int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
void
git_hash_sha1_ctx_cleanup
(
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
if
(
ctx
)
mbedtls_sha1_free
(
&
ctx
->
c
);
}
int
git_hash_sha1_init
(
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
mbedtls_sha1_init
(
&
ctx
->
c
);
mbedtls_sha1_starts
(
&
ctx
->
c
);
return
0
;
...
...
@@ -33,14 +33,14 @@ int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
int
git_hash_sha1_update
(
git_hash_sha1_ctx
*
ctx
,
const
void
*
data
,
size_t
len
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
mbedtls_sha1_update
(
&
ctx
->
c
,
data
,
len
);
return
0
;
}
int
git_hash_sha1_final
(
git_oid
*
out
,
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
mbedtls_sha1_finish
(
&
ctx
->
c
,
out
->
id
);
return
0
;
}
src/hash/sha1/openssl.c
View file @
3ff56dae
...
...
@@ -24,7 +24,7 @@ void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx)
int
git_hash_sha1_init
(
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
if
(
SHA1_Init
(
&
ctx
->
c
)
!=
1
)
{
git_error_set
(
GIT_ERROR_SHA1
,
"hash_openssl: failed to initialize hash context"
);
...
...
@@ -36,7 +36,7 @@ int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
int
git_hash_sha1_update
(
git_hash_sha1_ctx
*
ctx
,
const
void
*
data
,
size_t
len
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
if
(
SHA1_Update
(
&
ctx
->
c
,
data
,
len
)
!=
1
)
{
git_error_set
(
GIT_ERROR_SHA1
,
"hash_openssl: failed to update hash"
);
...
...
@@ -48,7 +48,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
int
git_hash_sha1_final
(
git_oid
*
out
,
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
if
(
SHA1_Final
(
out
->
id
,
&
ctx
->
c
)
!=
1
)
{
git_error_set
(
GIT_ERROR_SHA1
,
"hash_openssl: failed to finalize hash"
);
...
...
src/hash/sha1/win32.c
View file @
3ff56dae
...
...
@@ -164,7 +164,7 @@ GIT_INLINE(int) hash_cryptoapi_update(git_hash_sha1_ctx *ctx, const void *_data,
{
const
BYTE
*
data
=
(
BYTE
*
)
_data
;
assert
(
ctx
->
ctx
.
cryptoapi
.
valid
);
GIT_ASSERT
(
ctx
->
ctx
.
cryptoapi
.
valid
);
while
(
len
>
0
)
{
DWORD
chunk
=
(
len
>
MAXDWORD
)
?
MAXDWORD
:
(
DWORD
)
len
;
...
...
@@ -186,7 +186,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_sha1_ctx *ctx)
DWORD
len
=
20
;
int
error
=
0
;
assert
(
ctx
->
ctx
.
cryptoapi
.
valid
);
GIT_ASSERT
(
ctx
->
ctx
.
cryptoapi
.
valid
);
if
(
!
CryptGetHashParam
(
ctx
->
ctx
.
cryptoapi
.
hash_handle
,
HP_HASHVAL
,
out
->
id
,
&
len
,
0
))
{
git_error_set
(
GIT_ERROR_OS
,
"legacy hash data could not be finished"
);
...
...
@@ -286,7 +286,7 @@ int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
{
int
error
=
0
;
assert
(
ctx
);
GIT_ASSERT_ARG
(
ctx
);
/*
* When compiled with GIT_THREADS, the global hash_prov data is
...
...
@@ -303,27 +303,30 @@ int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx)
int
git_hash_sha1_init
(
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
&&
ctx
->
type
);
GIT_ASSERT_ARG
(
ctx
);
GIT_ASSERT_ARG
(
ctx
->
type
);
return
(
ctx
->
type
==
CNG
)
?
hash_cng_init
(
ctx
)
:
hash_cryptoapi_init
(
ctx
);
}
int
git_hash_sha1_update
(
git_hash_sha1_ctx
*
ctx
,
const
void
*
data
,
size_t
len
)
{
assert
(
ctx
&&
ctx
->
type
);
GIT_ASSERT_ARG
(
ctx
);
GIT_ASSERT_ARG
(
ctx
->
type
);
return
(
ctx
->
type
==
CNG
)
?
hash_cng_update
(
ctx
,
data
,
len
)
:
hash_cryptoapi_update
(
ctx
,
data
,
len
);
}
int
git_hash_sha1_final
(
git_oid
*
out
,
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
&&
ctx
->
type
);
GIT_ASSERT_ARG
(
ctx
);
GIT_ASSERT_ARG
(
ctx
->
type
);
return
(
ctx
->
type
==
CNG
)
?
hash_cng_final
(
out
,
ctx
)
:
hash_cryptoapi_final
(
out
,
ctx
);
}
void
git_hash_sha1_ctx_cleanup
(
git_hash_sha1_ctx
*
ctx
)
{
assert
(
ctx
);
if
(
ctx
->
type
==
CNG
)
if
(
!
ctx
)
return
;
else
if
(
ctx
->
type
==
CNG
)
hash_ctx_cng_cleanup
(
ctx
);
else
if
(
ctx
->
type
==
CRYPTOAPI
)
hash_ctx_cryptoapi_cleanup
(
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