| 70 | // context. |
| 71 | |
| 72 | void MD5::update (uint1 *input, uint4 input_length) { |
| 73 | |
| 74 | uint4 input_index, buffer_index; |
| 75 | uint4 buffer_space; // how much space is left in buffer |
| 76 | |
| 77 | if (finalized){ // so we can't update! |
| 78 | cerr << "MD5::update: Can't update a finalized digest!" << endl; |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | // Compute number of bytes mod 64 |
| 83 | buffer_index = (unsigned int)((count[0] >> 3) & 0x3F); |
| 84 | |
| 85 | // Update number of bits |
| 86 | if ( (count[0] += ((uint4) input_length << 3))<((uint4) input_length << 3) ) |
| 87 | count[1]++; |
| 88 | |
| 89 | count[1] += ((uint4)input_length >> 29); |
| 90 | |
| 91 | |
| 92 | buffer_space = 64 - buffer_index; // how much space is left in buffer |
| 93 | |
| 94 | // Transform as many times as possible. |
| 95 | if (input_length >= buffer_space) { // ie. we have enough to fill the buffer |
| 96 | // fill the rest of the buffer and transform |
| 97 | memcpy (buffer + buffer_index, input, buffer_space); |
| 98 | transform (buffer); |
| 99 | |
| 100 | // now, transform each 64-byte piece of the input, bypassing the buffer |
| 101 | for (input_index = buffer_space; input_index + 63 < input_length; |
| 102 | input_index += 64) |
| 103 | transform (input+input_index); |
| 104 | |
| 105 | buffer_index = 0; // so we can buffer remaining |
| 106 | } |
| 107 | else |
| 108 | input_index=0; // so we can buffer the whole input |
| 109 | |
| 110 | |
| 111 | // and here we do the buffering: |
| 112 | memcpy(buffer+buffer_index, input+input_index, input_length-input_index); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | |