[lib.scha] cleanup
This commit is contained in:
parent
544ee489a4
commit
046fed121a
|
@ -9,8 +9,8 @@ import (
|
||||||
/* (0) Static
|
/* (0) Static
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* (1) Constants */
|
/* (1) Constants */
|
||||||
const HBITSIZE uint32 = 512;
|
const HSIZE uint16 = sha512.Size;
|
||||||
const HSIZE uint16 = uint16(HBITSIZE / 8);
|
const HBITSIZE uint32 = uint32(HSIZE) * 8;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,14 +27,15 @@ func hash(input []byte) []byte{
|
||||||
/* (1) Create sha512 hasher */
|
/* (1) Create sha512 hasher */
|
||||||
hasher := sha512.New();
|
hasher := sha512.New();
|
||||||
|
|
||||||
/* (2) Set input to be hashed */
|
/* (2) Defer memory cleanup */
|
||||||
|
defer hasher.Reset();
|
||||||
|
|
||||||
|
/* (3) Set input to be hashed */
|
||||||
hasher.Write(input);
|
hasher.Write(input);
|
||||||
|
|
||||||
/* (3) Extract digest */
|
/* (4) Extract digest */
|
||||||
return hasher.Sum(nil);
|
return hasher.Sum(nil);
|
||||||
|
|
||||||
// digest := base64.StdEncoding.EncodeToString(container)
|
|
||||||
// fmt.Println(digest)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,24 +71,17 @@ func Hash(input []byte, depth uint, salt []byte, pepper []byte) ([]byte, error)
|
||||||
|
|
||||||
/* (2) Process first hash + salt */
|
/* (2) Process first hash + salt */
|
||||||
digest = hash( xor.ByteArray(input, salt) )
|
digest = hash( xor.ByteArray(input, salt) )
|
||||||
if depth > 0 { depth-- }
|
|
||||||
|
|
||||||
/* (3) Iterate @depth times */
|
/* (3) Iterate @depth times */
|
||||||
for depth > 0 {
|
for depth--; depth > 0; depth-- {
|
||||||
|
|
||||||
// 1. Add Pepper for last time
|
// Add Pepper only for last time
|
||||||
if( depth == 1 ){
|
if( depth == 1 ){
|
||||||
|
|
||||||
digest = hash( xor.ByteArray(digest, pepper) )
|
digest = hash( xor.ByteArray(digest, pepper) )
|
||||||
|
|
||||||
// 2. Else only hash
|
|
||||||
} else {
|
} else {
|
||||||
digest = hash(digest)
|
digest = hash(digest)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
depth--;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return digest, nil
|
return digest, nil
|
||||||
|
|
Loading…
Reference in New Issue