net.siisise.security.digest.RIPEMD Maven / Gradle / Ivy
/*
* Copyright 2024 okome.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.siisise.security.digest;
import net.siisise.lang.Bin;
import net.siisise.security.io.BlockOutputStream;
/**
* RACE Integrity Primitives Evalution Message Digest
*
* RIPEMD (オリジナル128bit) 1996年
* RIPEMD-128 (改良)
* RIPEMD-160
* RIPEMD-256
* RIPEMD-320
*
* @deprecated セキュリティ的に推奨しない 実装まだ
*/
@Deprecated
public class RIPEMD extends BlockMessageDigest {
int len = 20;
int[] ad;
public RIPEMD() {
super("RIPEMD"); // オリジナル?
}
public RIPEMD(String name) {
super(name);
if ( name.startsWith("RIPEMD-")) {
len = Integer.parseInt(name.substring(7)) / 8;
}
}
@Override
protected int engineGetDigestLength() {
return len;
}
@Override
public int getBitBlockLength() {
return 512;
}
@Override
protected byte[] engineDigest() {
long len = length;
// ラスト周
// padding
pac.write(new byte[]{(byte) 0x80});
int padlen = 512 - (int) ((len + 64 + 8) % 512);
pac.write(new byte[padlen / 8]);
byte[] lena = new byte[8];
for (int i = 0; i < 8; i++) {
lena[i] = (byte) len;
len >>>= 8;
}
pac.write(lena, 0, lena.length);
byte[] ret = new byte[this.len];
for (int i = 0; i < this.len; i++) {
ret[i] = (byte) (ad[i / 4] >>> ((i & 3) * 8));
}
engineReset();
return ret;
}
@Override
protected void engineReset() {
ad = new int[]{0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0};
length = 0;
pac = new BlockOutputStream(this);
}
@Override
public void blockWrite(byte[] src, int offset, int length) {
int[] s = Bin.btoli(src,offset,length);
for ( int i = 0; i < 16; i++ ) { // Round 1
}
for ( int i = 16; i < 32; i++ ) { // Round 2
}
for ( int i = 32; i < 48; i++ ) { // Round 3
}
for ( int i = 48; i < 64; i++ ) { // Round 4
}
for ( int i = 64; i < 80; i++ ) { // Round 5
}
throw new UnsupportedOperationException("Not supported yet.");
}
}