ext/iodine/fio.c
/**
Writes data to the SHA-2 buffer.
*/
Writes data to the SHA-2 buffer.
Writes data to the SHA - 2 buffer .
void fio_sha2_write(fio_sha2_s *s, const void *data, size_t len) {
  size_t in_buffer;
  size_t partial;
  if (s->type & 1) { 
    in_buffer = s->length.words[0] & 127;
    if (s->length.words[0] + len < s->length.words[0]) {
      s->length.words[1] = (s->length.words[1] << 1) | 1;
    }
    s->length.words[0] += len;
    partial = 128 - in_buffer;
    if (partial > len) {
      memcpy(s->buffer + in_buffer, data, len);
      return;
    }
    if (in_buffer) {
      memcpy(s->buffer + in_buffer, data, partial);
      len -= partial;
      data = (void *)((uintptr_t)data + partial);
      fio_sha2_perform_all_rounds(s, s->buffer);
    }
    while (len >= 128) {
      fio_sha2_perform_all_rounds(s, data);
      data = (void *)((uintptr_t)data + 128);
      len -= 128;
    }
    if (len) {
      memcpy(s->buffer + in_buffer, data, len);
    }
    return;
  }
  in_buffer = s->length.words[0] & 63;
  partial = 64 - in_buffer;
  s->length.words[0] += len;
  if (partial > len) {
    memcpy(s->buffer + in_buffer, data, len);
    return;
  }
  if (in_buffer) {
    memcpy(s->buffer + in_buffer, data, partial);
    len -= partial;
    data = (void *)((uintptr_t)data + partial);
    fio_sha2_perform_all_rounds(s, s->buffer);
  }
  while (len >= 64) {
    fio_sha2_perform_all_rounds(s, data);
    data = (void *)((uintptr_t)data + 64);
    len -= 64;
  }
  if (len) {
    memcpy(s->buffer + in_buffer, data, len);
  }
  return;
}
void fio_sha2_write ( fio_sha2_s * s , const void * data , size_t len ) { size_t in_buffer ; size_t partial ; if ( s -> type & 1 ) { in_buffer = s -> length . words [ 0 ] & 127 ; if ( s -> length . words [ 0 ] + len < s -> length . words [ 0 ] ) { s -> length . words [ 1 ] = ( s -> length . words [ 1 ] << 1 ) | 1 ; } s -> length . words [ 0 ] += len ; partial = 128 - in_buffer ; if ( partial > len ) { memcpy ( s -> buffer + in_buffer , data , len ) ; return ; } if ( in_buffer ) { memcpy ( s -> buffer + in_buffer , data , partial ) ; len -= partial ; data = ( void * ) ( ( uintptr_t ) data + partial ) ; fio_sha2_perform_all_rounds ( s , s -> buffer ) ; } while ( len >= 128 ) { fio_sha2_perform_all_rounds ( s , data ) ; data = ( void * ) ( ( uintptr_t ) data + 128 ) ; len -= 128 ; } if ( len ) { memcpy ( s -> buffer + in_buffer , data , len ) ; } return ; } in_buffer = s -> length . words [ 0 ] & 63 ; partial = 64 - in_buffer ; s -> length . words [ 0 ] += len ; if ( partial > len ) { memcpy ( s -> buffer + in_buffer , data , len ) ; return ; } if ( in_buffer ) { memcpy ( s -> buffer + in_buffer , data , partial ) ; len -= partial ; data = ( void * ) ( ( uintptr_t ) data + partial ) ; fio_sha2_perform_all_rounds ( s , s -> buffer ) ; } while ( len >= 64 ) { fio_sha2_perform_all_rounds ( s , data ) ; data = ( void * ) ( ( uintptr_t ) data + 64 ) ; len -= 64 ; } if ( len ) { memcpy ( s -> buffer + in_buffer , data , len ) ; } return ; }
Writes data to the SHA-2 buffer.
Writes data to the SHA - 2 buffer .
/* 512 type derived */ /* we are at wraping around the 64bit limit */ /* else... NOT 512 bits derived (64bit base) */