Index: contrib/pgcrypto/sha2.c =================================================================== RCS file: /opt/arc/cvs2/pgsql/contrib/pgcrypto/sha2.c,v retrieving revision 1.2 diff -u -c -r1.2 sha2.c *** contrib/pgcrypto/sha2.c 11 Jul 2005 15:07:59 -0000 1.2 --- contrib/pgcrypto/sha2.c 11 Jul 2005 15:20:33 -0000 *************** *** 42,52 **** #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 --- 42,47 ---- *************** *** 281,288 **** { if (context == NULL) return; ! bcopy(sha256_initial_hash_value, context->state, SHA256_DIGEST_LENGTH); ! bzero(context->buffer, SHA256_BLOCK_LENGTH); context->bitcount = 0; } --- 276,283 ---- { if (context == NULL) return; ! memcpy(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH); ! memset(context->buffer, 0, SHA256_BLOCK_LENGTH); context->bitcount = 0; } *************** *** 466,479 **** if (len >= freespace) { /* Fill the buffer completely and process it */ ! bcopy(data, &context->buffer[usedspace], 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); context->bitcount += len << 3; /* Clean up: */ usedspace = freespace = 0; --- 461,474 ---- if (len >= freespace) { /* Fill the buffer completely and process it */ ! 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 */ ! memcpy(&context->buffer[usedspace], data, len); context->bitcount += len << 3; /* Clean up: */ usedspace = freespace = 0; *************** *** 489,495 **** } if (len > 0) { /* There's left-overs, so save 'em */ ! bcopy(data, context->buffer, len); context->bitcount += len << 3; } /* Clean up: */ --- 484,490 ---- } if (len > 0) { /* There's left-overs, so save 'em */ ! memcpy(context->buffer, data, len); context->bitcount += len << 3; } /* Clean up: */ *************** *** 514,533 **** if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) { /* Set-up for the last transform: */ ! bzero(&context->buffer[usedspace], SHA256_SHORT_BLOCK_LENGTH - usedspace); } else { if (usedspace < SHA256_BLOCK_LENGTH) { ! bzero(&context->buffer[usedspace], 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); } } else { /* Set-up for the last transform: */ ! bzero(context->buffer, SHA256_SHORT_BLOCK_LENGTH); /* Begin padding with a 1 bit: */ *context->buffer = 0x80; --- 509,528 ---- if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) { /* Set-up for the last transform: */ ! memset(&context->buffer[usedspace], 0, SHA256_SHORT_BLOCK_LENGTH - usedspace); } else { if (usedspace < SHA256_BLOCK_LENGTH) { ! 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: */ ! memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); } } else { /* Set-up for the last transform: */ ! memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); /* Begin padding with a 1 bit: */ *context->buffer = 0x80; *************** *** 547,557 **** } } #endif ! bcopy(context->state, digest, SHA256_DIGEST_LENGTH); } /* Clean up state data: */ ! bzero(context, sizeof(*context)); usedspace = 0; } --- 542,552 ---- } } #endif ! memcpy(digest, context->state, SHA256_DIGEST_LENGTH); } /* Clean up state data: */ ! memset(context, 0, sizeof(*context)); usedspace = 0; } *************** *** 562,569 **** { if (context == NULL) return; ! bcopy(sha512_initial_hash_value, context->state, SHA512_DIGEST_LENGTH); ! bzero(context->buffer, SHA512_BLOCK_LENGTH); context->bitcount[0] = context->bitcount[1] = 0; } --- 557,564 ---- { if (context == NULL) return; ! memcpy(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH); ! memset(context->buffer, 0, SHA512_BLOCK_LENGTH); context->bitcount[0] = context->bitcount[1] = 0; } *************** *** 747,760 **** if (len >= freespace) { /* Fill the buffer completely and process it */ ! bcopy(data, &context->buffer[usedspace], 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); ADDINC128(context->bitcount, len << 3); /* Clean up: */ usedspace = freespace = 0; --- 742,755 ---- if (len >= freespace) { /* Fill the buffer completely and process it */ ! 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 */ ! memcpy(&context->buffer[usedspace], data, len); ADDINC128(context->bitcount, len << 3); /* Clean up: */ usedspace = freespace = 0; *************** *** 770,776 **** } if (len > 0) { /* There's left-overs, so save 'em */ ! bcopy(data, context->buffer, len); ADDINC128(context->bitcount, len << 3); } /* Clean up: */ --- 765,771 ---- } if (len > 0) { /* There's left-overs, so save 'em */ ! memcpy(context->buffer, data, len); ADDINC128(context->bitcount, len << 3); } /* Clean up: */ *************** *** 794,813 **** if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) { /* Set-up for the last transform: */ ! bzero(&context->buffer[usedspace], SHA512_SHORT_BLOCK_LENGTH - usedspace); } else { if (usedspace < SHA512_BLOCK_LENGTH) { ! bzero(&context->buffer[usedspace], 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); } } else { /* Prepare for final transform: */ ! bzero(context->buffer, SHA512_SHORT_BLOCK_LENGTH); /* Begin padding with a 1 bit: */ *context->buffer = 0x80; --- 789,808 ---- if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) { /* Set-up for the last transform: */ ! memset(&context->buffer[usedspace], 0, SHA512_SHORT_BLOCK_LENGTH - usedspace); } else { if (usedspace < SHA512_BLOCK_LENGTH) { ! 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: */ ! memset(context->buffer, 0, SHA512_BLOCK_LENGTH - 2); } } else { /* Prepare for final transform: */ ! memset(context->buffer, 0, SHA512_SHORT_BLOCK_LENGTH); /* Begin padding with a 1 bit: */ *context->buffer = 0x80; *************** *** 837,847 **** } } #endif ! bcopy(context->state, digest, SHA512_DIGEST_LENGTH); } /* Zero out state data */ ! bzero(context, sizeof(*context)); } --- 832,842 ---- } } #endif ! memcpy(digest, context->state, SHA512_DIGEST_LENGTH); } /* Zero out state data */ ! memset(context, 0, sizeof(*context)); } *************** *** 851,858 **** { if (context == NULL) return; ! bcopy(sha384_initial_hash_value, context->state, SHA512_DIGEST_LENGTH); ! bzero(context->buffer, SHA384_BLOCK_LENGTH); context->bitcount[0] = context->bitcount[1] = 0; } --- 846,853 ---- { if (context == NULL) return; ! memcpy(context->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH); ! memset(context->buffer, 0, SHA384_BLOCK_LENGTH); context->bitcount[0] = context->bitcount[1] = 0; } *************** *** 879,887 **** } } #endif ! bcopy(context->state, digest, SHA384_DIGEST_LENGTH); } /* Zero out state data */ ! bzero(context, sizeof(*context)); } --- 874,882 ---- } } #endif ! memcpy(digest, context->state, SHA384_DIGEST_LENGTH); } /* Zero out state data */ ! memset(context, 0, sizeof(*context)); }