Bcrypt.bend checks
raw source on the hub · import hhefesto-bcrypt@1.0.0.0/Bcrypt.bend as Bcrypt
2 imports
import Base import ./Pi.bend as Pi
Types
type bc.B source · line 38 · raw
Type
the state beside a block (l, r): what an enciphering hands back
bc.B@a:Array<U32> -> @l:U32 -> @r:U32 -> bc.B
type bc.Set source · line 330 · raw
Data
A text read: its cost, its salt's 22 characters, its hash's 31
bc.Set@cost:Nat -> @salt:String -> @hash:String -> bc.Set
Definitions
def bc.at source · line 42 · raw
@+i:U32 -> U32
where pi's i-th word goes: the first 18 are P's, the next 1024 the S-boxes'
def bc.load source · line 45 · raw
@xs:List<&2, U32> -> @a:Array<U32> -> @+i:U32 -> Array<U32>
def bc.init source · line 53 · raw
Array<U32>
Blowfish's initial state: pi's digits
def bc.f4 source · line 59 · raw
@r:Pair(Array<U32>, U32) -> @+s:U32 -> Pair(Array<U32>, U32)
def bc.f3 source · line 64 · raw
@r:Pair(Array<U32>, U32) -> @+s:U32 -> @+x:U32 -> Pair(Array<U32>, U32)
def bc.f2 source · line 69 · raw
@r:Pair(Array<U32>, U32) -> @+s0:U32 -> @+x:U32 -> Pair(Array<U32>, U32)
def bc.f1 source · line 74 · raw
@r:Pair(Array<U32>, U32) -> @+x:U32 -> Pair(Array<U32>, U32)
def bc.f source · line 80 · raw
@a:Array<U32> -> @+x:U32 -> Pair(Array<U32>, U32)
Blowfish's F: ((S0[x >> 24] + S1[x >> 16 & 255]) ^ S2[x >> 8 & 255]) + S3[x & 255]
def bc.half.p source · line 83 · raw
@r:Pair(Array<U32>, U32) -> @+fx:U32 -> @+y:U32 -> Pair(Array<U32>, U32)
def bc.half.f source · line 88 · raw
@r:Pair(Array<U32>, U32) -> @+i:U32 -> @+y:U32 -> Pair(Array<U32>, U32)
def bc.half source · line 94 · raw
@a:Array<U32> -> @+x:U32 -> @+y:U32 -> @+i:U32 -> Pair(Array<U32>, U32)
a half round: y ^ F(x) ^ P[i]
def bc.go source · line 99 · raw
@n:Nat -> @r:Pair(Array<U32>, U32) -> @+prev:U32 -> @+i:U32 -> bc.B
n half rounds from P[i]: cur the half last made (beside the array),
prev the other; they end as (cur, prev)
def bc.enc.fin source · line 106 · raw
@r:Pair(Array<U32>, U32) -> @+xl:U32 -> @+xr:U32 -> bc.B
def bc.enc.out source · line 111 · raw
@r:bc.B -> bc.B
def bc.enc.in source · line 116 · raw
@r:Pair(Array<U32>, U32) -> @+l:U32 -> @+x:U32 -> bc.B
def bc.enc source · line 123 · raw
@a:Array<U32> -> @+l:U32 -> @+r:U32 -> bc.B
Blowfish's encryption of the block (l, r) under the state: l ^= P[0], 16 rounds, then (r ^ P[17], l)
def bc.xorp.at source · line 129 · raw
@r:Pair(Array<U32>, U32) -> @+i:U32 -> @+k:U32 -> Array<U32>
def bc.xorp source · line 135 · raw
@ks:List<&2, U32> -> @a:Array<U32> -> @+i:U32 -> Array<U32>
the key's words xored into P, from P[i]
def bc.store source · line 142 · raw
@r:bc.B -> @+at:U32 -> bc.B
def bc.fill source · line 149 · raw
@n:Nat -> @r:bc.B -> @+at:U32 -> @+s0:U32 -> @+s1:U32 -> @+s2:U32 -> @+s3:U32 -> bc.B
n blocks enciphered in a chain, each block first xored with the salt's
next two words (s0, s1: the four take turns), stored from at on
def bc.arr source · line 156 · raw
@r:bc.B -> Array<U32>
def bc.expand.s source · line 162 · raw
@r:bc.B -> @+s0:U32 -> @+s1:U32 -> @+s2:U32 -> @+s3:U32 -> Array<U32>
(P's 9 blocks used the salt's words 0 to 17: the S-boxes' start at word 2)
def bc.expand source · line 168 · raw
@a:Array<U32> -> @+ks:List<&2, U32> -> @+s0:U32 -> @+s1:U32 -> @+s2:U32 -> @+s3:U32 -> Array<U32>
ExpandKey(state, salt, key): the key's 18 words xored into P, then P and the S-boxes made again in a chain of encipherings, each block xored first with the salt's next words (s0..s3; zeros for no salt)
def bc.rounds source · line 172 · raw
@n:Nat -> @a:Array<U32> -> @+ks:List<&2, U32> -> @+ss:List<&2, U32> -> Array<U32>
n times ExpandKey(state, 0, key), then ExpandKey(state, 0, salt)
def bc.cyc source · line 183 · raw
@n:Nat -> @cur:List<&2, U32> -> @+all:List<&2, U32> -> List<&2, U32>
n bytes of all, taken over and over (from cur, the rest of this turn)
def bc.words source · line 195 · raw
@bs:List<&2, U32> -> List<&2, U32>
bytes as big-endian words, 4 a word
def bc.bytes source · line 203 · raw
@ws:List<&2, U32> -> List<&2, U32>
words as big-endian bytes
def bc.setup source · line 211 · raw
@+ks:List<&2, U32> -> @sw:List<&2, U32> -> Array<U32>
EksBlowfishSetup(cost, salt, key)
def bc.eks source · line 218 · raw
@+cost:Nat -> @+salt:List<&2, U32> -> @+key:List<&2, U32> -> Array<U32>
def bc.ecb source · line 221 · raw
@n:Nat -> @r:bc.B -> bc.B
def bc.out3 source · line 228 · raw
@r:bc.B -> @+w0:U32 -> @+w1:U32 -> @+w2:U32 -> @+w3:U32 -> List<&2, U32>
def bc.out2 source · line 233 · raw
@r:bc.B -> @+w0:U32 -> @+w1:U32 -> @+w4:U32 -> @+w5:U32 -> List<&2, U32>
def bc.out1 source · line 238 · raw
@r:bc.B -> @+w2:U32 -> @+w3:U32 -> @+w4:U32 -> @+w5:U32 -> List<&2, U32>
def bc.text.bytes source · line 243 · raw
@s:String -> List<&2, U32>
def bc.cipher.ws source · line 250 · raw
@a:Array<U32> -> @ws:List<&2, U32> -> List<&2, U32>
def bc.cipher source · line 259 · raw
@a:Array<U32> -> List<&2, U32>
"OrpheanBeholderScryDoubt" (6 words) enciphered 64 times under the state (each of its 3 blocks alone: ECB)
def bc.raw source · line 263 · raw
@+cost:Nat -> @+salt:List<&2, U32> -> @+pw:List<&2, U32> -> List<&2, U32>
bcrypt's 23 bytes for the cost, the salt (16 bytes) and the password's bytes
def bc.b64.c source · line 270 · raw
@+v:U32 -> Char
a 6-bit value's character: "./", "A".."Z", "a".."z", "0".."9"
def bc.b64.v source · line 274 · raw
@+c:U32 -> U32
a character's 6-bit value (64: none)
def bc.enc64 source · line 284 · raw
@bs:List<&2, U32> -> String
bytes as text: 3 bytes to 4 characters; a last 1 or 2 to 2 or 3
def bc.dec64 source · line 297 · raw
@s:String -> List<&2, U32>
text as bytes, the inverse (the bits past the last whole byte dropped)
def bc.b64.ok source · line 312 · raw
@s:String -> Bool
every character one of bcrypt's 64
def bc.two source · line 322 · raw
@+n:Nat -> String
def bc.hash source · line 326 · raw
@+cost:Nat -> @+salt:List<&2, U32> -> @+pw:List<&2, U32> -> String
The text of bcrypt for the cost (4..31), the salt (16 bytes) and the password's bytes
def bc.digit source · line 333 · raw
@+c:U32 -> Bool
def bc.read.at source · line 336 · raw
@ok:Bool -> @+cost:U32 -> @+rest:String -> Maybe<&2, bc.Set>
def bc.read source · line 344 · raw
@s:String -> Maybe<&2, bc.Set>
"$2y$", "$2b$" or "$2a$", two digits (04..31), "$", 53 of bcrypt's characters
def bc.check.set source · line 355 · raw
@m:Maybe<&2, bc.Set> -> @+pw:List<&2, U32> -> Bool
def bc.check source · line 364 · raw
@+pw:List<&2, U32> -> @text:String -> Bool
Whether the password's bytes are right for the text: the hash they give with its cost and salt is its hash (a text that does not read: never)