mirror of
https://github.com/sheumann/65816-crypto.git
synced 2024-12-01 04:49:15 +00:00
Tweaks to SHA-1 update and finalization code.
This commit is contained in:
parent
8b17a15ada
commit
0ad5d39f07
34
sha1.cc
34
sha1.cc
@ -17,13 +17,21 @@ void sha1_update(struct sha1_context *context,
|
|||||||
unsigned long length)
|
unsigned long length)
|
||||||
{
|
{
|
||||||
unsigned int extra = context->extra;
|
unsigned int extra = context->extra;
|
||||||
|
unsigned long oldlength = context->length;
|
||||||
|
|
||||||
context->length += length;
|
if ((context->length += length) < oldlength)
|
||||||
|
context->length2++;
|
||||||
|
|
||||||
if (extra > 0) {
|
if (extra > 0) {
|
||||||
if (length >= 64 - extra) {
|
if (length >= 64 - extra) {
|
||||||
memcpy(&context->chunk[extra], data, 64 - extra);
|
memcpy(&context->chunk[extra], data, 64 - extra);
|
||||||
sha1_processchunk(context);
|
asm {
|
||||||
|
phd
|
||||||
|
lda context
|
||||||
|
tcd
|
||||||
|
jsl SHA1_PROCESSCHUNK
|
||||||
|
pld
|
||||||
|
}
|
||||||
length -= 64 - extra;
|
length -= 64 - extra;
|
||||||
data += 64 - extra;
|
data += 64 - extra;
|
||||||
} else {
|
} else {
|
||||||
@ -35,7 +43,13 @@ void sha1_update(struct sha1_context *context,
|
|||||||
|
|
||||||
while (length >= 64) {
|
while (length >= 64) {
|
||||||
memcpy(&context->chunk, data, 64);
|
memcpy(&context->chunk, data, 64);
|
||||||
sha1_processchunk(context);
|
asm {
|
||||||
|
phd
|
||||||
|
lda context
|
||||||
|
tcd
|
||||||
|
jsl SHA1_PROCESSCHUNK
|
||||||
|
pld
|
||||||
|
}
|
||||||
length -= 64;
|
length -= 64;
|
||||||
data += 64;
|
data += 64;
|
||||||
}
|
}
|
||||||
@ -54,16 +68,22 @@ void sha1_finalize(struct sha1_context *context)
|
|||||||
memset(&context->chunk[extra], 0, 64 - extra);
|
memset(&context->chunk[extra], 0, 64 - extra);
|
||||||
|
|
||||||
if (extra > 64 - 8) {
|
if (extra > 64 - 8) {
|
||||||
sha1_processchunk(context);
|
asm {
|
||||||
memset(&context->chunk, 0, 64);
|
phd
|
||||||
|
lda context
|
||||||
|
tcd
|
||||||
|
jsl SHA1_PROCESSCHUNK
|
||||||
|
pld
|
||||||
|
}
|
||||||
|
memset(&context->chunk, 0, 64 - 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append total length in bits */
|
|
||||||
asm {
|
asm {
|
||||||
phd
|
phd
|
||||||
lda context
|
lda context
|
||||||
tcd
|
tcd
|
||||||
|
|
||||||
|
/* Append total length in bits */
|
||||||
asl length_offset
|
asl length_offset
|
||||||
rol length_offset+2
|
rol length_offset+2
|
||||||
rol length_offset+4
|
rol length_offset+4
|
||||||
@ -90,8 +110,10 @@ void sha1_finalize(struct sha1_context *context)
|
|||||||
xba
|
xba
|
||||||
sta data_offset+62
|
sta data_offset+62
|
||||||
|
|
||||||
|
/* Process final block */
|
||||||
jsl SHA1_PROCESSCHUNK
|
jsl SHA1_PROCESSCHUNK
|
||||||
|
|
||||||
|
/* Flip hash state words to big-endian order */
|
||||||
lda hash_offset
|
lda hash_offset
|
||||||
xba
|
xba
|
||||||
tay
|
tay
|
||||||
|
Loading…
Reference in New Issue
Block a user