ED2KHasherpublic class ED2KHasher extends Object
Fields Summary |
---|
public static final int | BLOCK_SIZE | protected MD4Hasher | current_hasher | protected MD4Hasher | block_hasher | protected int | current_bytes |
Constructors Summary |
---|
public ED2KHasher()
|
Methods Summary |
---|
public byte[] | getDigest()
// data that is a multiple of BLOCK_SIZE needs to have a null MD4 hash appended
if ( current_bytes == BLOCK_SIZE ){
if ( block_hasher == null ){
block_hasher = new MD4Hasher();
}
block_hasher.update( current_hasher.getDigest());
current_hasher = new MD4Hasher();
}
if ( block_hasher == null ){
return( current_hasher.getDigest());
}else{
if ( current_bytes > 0 ){
block_hasher.update( current_hasher.getDigest());
}
return( block_hasher.getDigest());
}
| public void | update(byte[] data)
update( data, 0, data.length );
| public void | update(byte[] data, int pos, int len)
int rem = len;
while( rem > 0 ){
int space = BLOCK_SIZE - current_bytes;
if ( rem <= space ){
current_hasher.update( data, pos, rem );
current_bytes += rem;
break;
}else{
if ( block_hasher == null ){
block_hasher = new MD4Hasher();
}
if ( space == 0 ){
block_hasher.update( current_hasher.getDigest());
current_hasher = new MD4Hasher();
current_bytes = 0;
}else{
current_hasher.update( data, pos, space );
pos += space;
rem -= space;
current_bytes += space;
}
}
}
|
|