Top Description Inners Fields Constructors Methods
org.eclipse.jgit.util.sha1

pack-priv Class SHA1Java

extends SHA1
Class Inheritance
Static Imports
java.lang.Integer.lowestOneBit, .Integer.numberOfTrailingZeros, .Integer.rotateLeft, .Integer.rotateRight

Pure Java implementation of SHA-1 from FIPS 180-1 / RFC 3174.

See RFC 3174.

Unlike MessageDigest, this implementation includes the algorithm used by sha1dc to detect cryptanalytic collision attacks against SHA-1, such as the one used by SHAttered. See sha1collisiondetection for more information.

When detectCollision is true (default), this implementation throws org.eclipse.jgit.util.sha1.Sha1CollisionException from any digest method if a potential collision was detected.

Since
4.7

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final byte[]
buffer

Buffer to accumulate partial blocks to 64 byte alignment.

private static final boolean
private boolean
private boolean
private final SHA1Java.State
h

private final SHA1Java.State
private final SHA1Java.State
private long
length

Total number of bytes in the message.

private static final Logger
private final SHA1Java.State
private final SHA1Java.State
private final int[]
w

private final int[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
compress(byte[] block, int p)

private void
public byte[]

Returns:

the bytes for the resulting hash.
digest
()

Implements abstract org.eclipse.jgit.util.sha1.SHA1.digest.

Finish the digest and return the resulting hash.

public void
digest(MutableObjectId
destination to copy the digest to.
id
)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.digest.

Finish the digest and return the resulting hash.

private static boolean
private void
public boolean

Returns:

true if a likely collision was detected.
hasCollision
()

Implements abstract org.eclipse.jgit.util.sha1.SHA1.hasCollision.

Check if a collision was detected.

private void
initBlock(byte[] block, int p)

private void
recompress(int t)

public SHA1

Returns:

this.
reset
()

Implements abstract org.eclipse.jgit.util.sha1.SHA1.reset.

Reset this instance to compute another hash.

private static int
s1(int a, int b, int c, int d, int w_t)

private static int
s2(int a, int b, int c, int d, int w_t)

private static int
s3(int a, int b, int c, int d, int w_t)

private static int
s4(int a, int b, int c, int d, int w_t)

public SHA1

Returns:

this
setDetectCollision
(boolean
a boolean.
detect
)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.setDetectCollision.

Enable likely collision detection.

public ObjectId

Returns:

the ObjectId for the resulting hash.
toObjectId
()

Implements abstract org.eclipse.jgit.util.sha1.SHA1.toObjectId.

Finish the digest and return the resulting hash.

public void
update(byte
a byte.
b
)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.update.

Update the digest computation by adding a byte.

public void
update(byte[]
input array of bytes.
in
)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.update.

Update the digest computation by adding bytes to the message.

public void
update(byte[]
input array of bytes.
in
,
int
offset to start at from in.
p
,
int
number of bytes to hash.
len
)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.update.

Update the digest computation by adding bytes to the message.

Inherited from org.eclipse.jgit.util.sha1.SHA1:
newInstance

Field Detail

bufferback to summary
private final byte[] buffer

Buffer to accumulate partial blocks to 64 byte alignment.

DETECT_COLLISIONSback to summary
private static final boolean DETECT_COLLISIONS
detectCollisionback to summary
private boolean detectCollision
foundCollisionback to summary
private boolean foundCollision
hback to summary
private final SHA1Java.State h
hInback to summary
private final SHA1Java.State hIn
hTmpback to summary
private final SHA1Java.State hTmp
lengthback to summary
private long length

Total number of bytes in the message.

LOGback to summary
private static final Logger LOG
state58back to summary
private final SHA1Java.State state58
state65back to summary
private final SHA1Java.State state65
wback to summary
private final int[] w
w2back to summary
private final int[] w2

Constructor Detail

SHA1Javaback to summary
pack-priv SHA1Java()

Method Detail

compressback to summary
private void compress(byte[] block, int p)
compressback to summary
private void compress()
digestback to summary
public byte[] digest() throws Sha1CollisionException

Implements abstract org.eclipse.jgit.util.sha1.SHA1.digest.

Finish the digest and return the resulting hash.

Once digest() is called, this instance should be discarded.

Returns:byte[]

the bytes for the resulting hash.

Annotations
@Override
Exceptions
Sha1CollisionException:
if a collision was detected and safeHash is false.
digestback to summary
public void digest(MutableObjectId id) throws Sha1CollisionException

Implements abstract org.eclipse.jgit.util.sha1.SHA1.digest.

Finish the digest and return the resulting hash.

Once digest() is called, this instance should be discarded.

Parameters
id:MutableObjectId

destination to copy the digest to.

Annotations
@Override
Exceptions
Sha1CollisionException:
if a collision was detected and safeHash is false.
eqback to summary
private static boolean eq(SHA1Java.State q, SHA1Java.State r)
finishback to summary
private void finish()
hasCollisionback to summary
public boolean hasCollision()

Implements abstract org.eclipse.jgit.util.sha1.SHA1.hasCollision.

Check if a collision was detected.

This method only returns an accurate result after the digest was obtained through digest(), digest(MutableObjectId) or toObjectId(), as the hashing function must finish processing to know the final state.

Returns:boolean

true if a likely collision was detected.

Annotations
@Override
initBlockback to summary
private void initBlock(byte[] block, int p)
recompressback to summary
private void recompress(int t)
resetback to summary
public SHA1 reset()

Implements abstract org.eclipse.jgit.util.sha1.SHA1.reset.

Reset this instance to compute another hash.

Returns:SHA1

this.

Annotations
@Override
s1back to summary
private static int s1(int a, int b, int c, int d, int w_t)
s2back to summary
private static int s2(int a, int b, int c, int d, int w_t)
s3back to summary
private static int s3(int a, int b, int c, int d, int w_t)
s4back to summary
private static int s4(int a, int b, int c, int d, int w_t)
setDetectCollisionback to summary
public SHA1 setDetectCollision(boolean detect)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.setDetectCollision.

Enable likely collision detection.

Default is true.

May also be set by system property: -Dorg.eclipse.jgit.util.sha1.detectCollision=true.

Parameters
detect:boolean

a boolean.

Returns:SHA1

this

Annotations
@Override
toObjectIdback to summary
public ObjectId toObjectId() throws Sha1CollisionException

Implements abstract org.eclipse.jgit.util.sha1.SHA1.toObjectId.

Finish the digest and return the resulting hash.

Once digest() is called, this instance should be discarded.

Returns:ObjectId

the ObjectId for the resulting hash.

Annotations
@Override
Exceptions
Sha1CollisionException:
if a collision was detected and safeHash is false.
updateback to summary
public void update(byte b)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.update.

Update the digest computation by adding a byte.

Parameters
b:byte

a byte.

Annotations
@Override
updateback to summary
public void update(byte[] in)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.update.

Update the digest computation by adding bytes to the message.

Parameters
in:byte[]

input array of bytes.

Annotations
@Override
updateback to summary
public void update(byte[] in, int p, int len)

Implements abstract org.eclipse.jgit.util.sha1.SHA1.update.

Update the digest computation by adding bytes to the message.

Parameters
in:byte[]

input array of bytes.

p:int

offset to start at from in.

len:int

number of bytes to hash.

Annotations
@Override
org.eclipse.jgit.util.sha1 back to summary

private final Class SHA1Java.State

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
a

pack-priv int
b

pack-priv int
c

pack-priv int
d

pack-priv int
e

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv final void
init()

pack-priv final void
save(int a1, int b1, int c1, int d1, int e1)

pack-priv ObjectId
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
pack-priv int a
bback to summary
pack-priv int b
cback to summary
pack-priv int c
dback to summary
pack-priv int d
eback to summary
pack-priv int e

Constructor Detail

Stateback to summary
private State()

Method Detail

initback to summary
pack-priv final void init()
saveback to summary
pack-priv final void save(int a1, int b1, int c1, int d1, int e1)
toObjectIdback to summary
pack-priv ObjectId toObjectId()