Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
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
Abuhujair Javed
Postgres FD Implementation
Commits
067a5cdb
Commit
067a5cdb
authored
Jul 11, 2005
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid bzero/bxopy in favor of more standard library routines.
Marko Kreen
parent
e997758c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
32 deletions
+27
-32
contrib/pgcrypto/sha2.c
contrib/pgcrypto/sha2.c
+27
-32
No files found.
contrib/pgcrypto/sha2.c
View file @
067a5cdb
...
...
@@ -33,7 +33,7 @@
*
* $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
*
* $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.
2 2005/07/11 15:07:59
tgl Exp $
* $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.
3 2005/07/11 15:40:38
tgl Exp $
*/
#include "postgres.h"
...
...
@@ -42,11 +42,6 @@
#include "sha2.h"
#undef bcopy
#undef bzero
#define bcopy(src, dst, len) memcpy((dst), (src), (len))
#define bzero(ptr, len) memset((ptr), 0, (len))
/*
* UNROLLED TRANSFORM LOOP NOTE:
* You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
...
...
@@ -281,8 +276,8 @@ SHA256_Init(SHA256_CTX *context)
{
if
(
context
==
NULL
)
return
;
bcopy
(
sha256_initial_hash_value
,
context
->
stat
e
,
SHA256_DIGEST_LENGTH
);
bzero
(
context
->
buffer
,
SHA256_BLOCK_LENGTH
);
memcpy
(
context
->
state
,
sha256_initial_hash_valu
e
,
SHA256_DIGEST_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA256_BLOCK_LENGTH
);
context
->
bitcount
=
0
;
}
...
...
@@ -466,14 +461,14 @@ SHA256_Update(SHA256_CTX *context, const uint8 *data, size_t len)
if
(
len
>=
freespace
)
{
/* Fill the buffer completely and process it */
bcopy
(
data
,
&
context
->
buffer
[
usedspace
]
,
freespace
);
memcpy
(
&
context
->
buffer
[
usedspace
],
data
,
freespace
);
context
->
bitcount
+=
freespace
<<
3
;
len
-=
freespace
;
data
+=
freespace
;
SHA256_Transform
(
context
,
context
->
buffer
);
}
else
{
/* The buffer is not yet full */
bcopy
(
data
,
&
context
->
buffer
[
usedspace
]
,
len
);
memcpy
(
&
context
->
buffer
[
usedspace
],
data
,
len
);
context
->
bitcount
+=
len
<<
3
;
/* Clean up: */
usedspace
=
freespace
=
0
;
...
...
@@ -489,7 +484,7 @@ SHA256_Update(SHA256_CTX *context, const uint8 *data, size_t len)
}
if
(
len
>
0
)
{
/* There's left-overs, so save 'em */
bcopy
(
data
,
context
->
buffer
,
len
);
memcpy
(
context
->
buffer
,
data
,
len
);
context
->
bitcount
+=
len
<<
3
;
}
/* Clean up: */
...
...
@@ -514,20 +509,20 @@ SHA256_Final(uint8 digest[], SHA256_CTX *context)
if
(
usedspace
<=
SHA256_SHORT_BLOCK_LENGTH
)
{
/* Set-up for the last transform: */
bzero
(
&
context
->
buffer
[
usedspace
]
,
SHA256_SHORT_BLOCK_LENGTH
-
usedspace
);
memset
(
&
context
->
buffer
[
usedspace
],
0
,
SHA256_SHORT_BLOCK_LENGTH
-
usedspace
);
}
else
{
if
(
usedspace
<
SHA256_BLOCK_LENGTH
)
{
bzero
(
&
context
->
buffer
[
usedspace
]
,
SHA256_BLOCK_LENGTH
-
usedspace
);
memset
(
&
context
->
buffer
[
usedspace
],
0
,
SHA256_BLOCK_LENGTH
-
usedspace
);
}
/* Do second-to-last transform: */
SHA256_Transform
(
context
,
context
->
buffer
);
/* And set-up for the last transform: */
bzero
(
context
->
buffer
,
SHA256_SHORT_BLOCK_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA256_SHORT_BLOCK_LENGTH
);
}
}
else
{
/* Set-up for the last transform: */
bzero
(
context
->
buffer
,
SHA256_SHORT_BLOCK_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA256_SHORT_BLOCK_LENGTH
);
/* Begin padding with a 1 bit: */
*
context
->
buffer
=
0x80
;
...
...
@@ -547,11 +542,11 @@ SHA256_Final(uint8 digest[], SHA256_CTX *context)
}
}
#endif
bcopy
(
context
->
state
,
digest
,
SHA256_DIGEST_LENGTH
);
memcpy
(
digest
,
context
->
state
,
SHA256_DIGEST_LENGTH
);
}
/* Clean up state data: */
bzero
(
context
,
sizeof
(
*
context
));
memset
(
context
,
0
,
sizeof
(
*
context
));
usedspace
=
0
;
}
...
...
@@ -562,8 +557,8 @@ SHA512_Init(SHA512_CTX *context)
{
if
(
context
==
NULL
)
return
;
bcopy
(
sha512_initial_hash_value
,
context
->
stat
e
,
SHA512_DIGEST_LENGTH
);
bzero
(
context
->
buffer
,
SHA512_BLOCK_LENGTH
);
memcpy
(
context
->
state
,
sha512_initial_hash_valu
e
,
SHA512_DIGEST_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA512_BLOCK_LENGTH
);
context
->
bitcount
[
0
]
=
context
->
bitcount
[
1
]
=
0
;
}
...
...
@@ -747,14 +742,14 @@ SHA512_Update(SHA512_CTX *context, const uint8 *data, size_t len)
if
(
len
>=
freespace
)
{
/* Fill the buffer completely and process it */
bcopy
(
data
,
&
context
->
buffer
[
usedspace
]
,
freespace
);
memcpy
(
&
context
->
buffer
[
usedspace
],
data
,
freespace
);
ADDINC128
(
context
->
bitcount
,
freespace
<<
3
);
len
-=
freespace
;
data
+=
freespace
;
SHA512_Transform
(
context
,
context
->
buffer
);
}
else
{
/* The buffer is not yet full */
bcopy
(
data
,
&
context
->
buffer
[
usedspace
]
,
len
);
memcpy
(
&
context
->
buffer
[
usedspace
],
data
,
len
);
ADDINC128
(
context
->
bitcount
,
len
<<
3
);
/* Clean up: */
usedspace
=
freespace
=
0
;
...
...
@@ -770,7 +765,7 @@ SHA512_Update(SHA512_CTX *context, const uint8 *data, size_t len)
}
if
(
len
>
0
)
{
/* There's left-overs, so save 'em */
bcopy
(
data
,
context
->
buffer
,
len
);
memcpy
(
context
->
buffer
,
data
,
len
);
ADDINC128
(
context
->
bitcount
,
len
<<
3
);
}
/* Clean up: */
...
...
@@ -794,20 +789,20 @@ SHA512_Last(SHA512_CTX *context)
if
(
usedspace
<=
SHA512_SHORT_BLOCK_LENGTH
)
{
/* Set-up for the last transform: */
bzero
(
&
context
->
buffer
[
usedspace
]
,
SHA512_SHORT_BLOCK_LENGTH
-
usedspace
);
memset
(
&
context
->
buffer
[
usedspace
],
0
,
SHA512_SHORT_BLOCK_LENGTH
-
usedspace
);
}
else
{
if
(
usedspace
<
SHA512_BLOCK_LENGTH
)
{
bzero
(
&
context
->
buffer
[
usedspace
]
,
SHA512_BLOCK_LENGTH
-
usedspace
);
memset
(
&
context
->
buffer
[
usedspace
],
0
,
SHA512_BLOCK_LENGTH
-
usedspace
);
}
/* Do second-to-last transform: */
SHA512_Transform
(
context
,
context
->
buffer
);
/* And set-up for the last transform: */
bzero
(
context
->
buffer
,
SHA512_BLOCK_LENGTH
-
2
);
memset
(
context
->
buffer
,
0
,
SHA512_BLOCK_LENGTH
-
2
);
}
}
else
{
/* Prepare for final transform: */
bzero
(
context
->
buffer
,
SHA512_SHORT_BLOCK_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA512_SHORT_BLOCK_LENGTH
);
/* Begin padding with a 1 bit: */
*
context
->
buffer
=
0x80
;
...
...
@@ -837,11 +832,11 @@ SHA512_Final(uint8 digest[], SHA512_CTX *context)
}
}
#endif
bcopy
(
context
->
state
,
digest
,
SHA512_DIGEST_LENGTH
);
memcpy
(
digest
,
context
->
state
,
SHA512_DIGEST_LENGTH
);
}
/* Zero out state data */
bzero
(
context
,
sizeof
(
*
context
));
memset
(
context
,
0
,
sizeof
(
*
context
));
}
...
...
@@ -851,8 +846,8 @@ SHA384_Init(SHA384_CTX *context)
{
if
(
context
==
NULL
)
return
;
bcopy
(
sha384_initial_hash_value
,
context
->
stat
e
,
SHA512_DIGEST_LENGTH
);
bzero
(
context
->
buffer
,
SHA384_BLOCK_LENGTH
);
memcpy
(
context
->
state
,
sha384_initial_hash_valu
e
,
SHA512_DIGEST_LENGTH
);
memset
(
context
->
buffer
,
0
,
SHA384_BLOCK_LENGTH
);
context
->
bitcount
[
0
]
=
context
->
bitcount
[
1
]
=
0
;
}
...
...
@@ -879,9 +874,9 @@ SHA384_Final(uint8 digest[], SHA384_CTX *context)
}
}
#endif
bcopy
(
context
->
state
,
digest
,
SHA384_DIGEST_LENGTH
);
memcpy
(
digest
,
context
->
state
,
SHA384_DIGEST_LENGTH
);
}
/* Zero out state data */
bzero
(
context
,
sizeof
(
*
context
));
memset
(
context
,
0
,
sizeof
(
*
context
));
}
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