###### tags: `blockchain` # keccak flow ## 什麼是加密雜湊演算法(cryptographic Hash) 密碼學一種常見的加密手段,透過輸入不定長度的輸入產生固定長度的hash值。 https://zh.wikipedia.org/zh-tw/%E5%AF%86%E7%A2%BC%E9%9B%9C%E6%B9%8A%E5%87%BD%E6%95%B8 雜湊演算法有幾個特性 1. 同樣的輸入訊息 只會產生同樣的hash 2. 運算本身是單向性的 從訊息到產生hash 要得知訊息只能透過暴力窮舉 3. 儘管輸入只有一個bit改變 其輸出應產生大量的改變 4. 減少碰撞(collision)的可能 不同的訊息產生同樣的hash ## keccak(SHA3) 來自FIPS PUB 202的SHA-3標準 keccak被人熟悉於使用sponge construction,將資料像海綿一樣吸入處理,而後進行輸出, permutations是用於資料處理流程中的函式 ### permutations 其狀態是由5x5的資料塊組成 有七種keccak-f permutations denoted Keccak-f[b] b∈{25,50,100,200,400,800,1600}代表permutations輸入的長度 等於想輸入的資料長度 每種長度 w∈{1,2,4,8,16,32,64} b=25w w代表單個資料塊長度的意思 若要實現 64bit 代表 w=64 b=1600 keccak-f{b} 可以運行64bit cpu ### sponge function 用得到的 Keccak[r,c]海綿函式,其function格式由capacity c and bitrate r 組成 通過特定的padding處理輸入資料 用於建構keccak-f{r+c} Keccak-f 與隨機排序不同 不具有隨機排序的顯著傳播屬性 The Keccak-f permutations should have no propagation properties significantly different from that of a random permutation 而keccak的海綿函式稱為緊湊海綿策略,意味著攻擊自海棉函式的隨機選擇排序可以被區隔開來,透過建立一個排序f函式,該函式不具有可利用的攻擊屬性,稱之為結構區分符。 在keccak中f排序透過透過θ、ρ、π、χ、ι 五個函式,完成多種不同的資料置換,其中有r[x,y] rotation offsets RC[i] round constants rot(W,r) bitwise cyclic shift operation等等方法, 海綿函式主要有兩個階段,填充階段將資料進行XOR運算後丟入f排序不斷更新直到填充結束,擠壓階段則透過排序f不斷輸出資料直到滿足所需的長度為止。 https://keccak.team/keccak_specs_summary.html#roundConstants 1. these results show that any attack against a sponge function implies that the permutation it uses can be distinguished from a typical randomly-chosen permutation, which we called the hermetic sponge strategy: adopting the sponge construction and building an underlying permutation f that should not have any properties exploitable in attacks. We have called such properties structural distinguishers (https://keccak.team/sponge_duplex.html) 2. The design philosophy underlying Kђѐѐюј is the hermetic sponge strategy. This consists of using the sponge construction for having provable security against all generic aĴacks and calling a permutation (or transformation) that should not have structural properties with the exception of a compact description (來自FIPS 202論文) (https://keccak.team/files/Keccak-reference-3.0.pdf) https://crypto.stackexchange.com/questions/38050/can-we-exchange-the-permutation-of-a-sponge-construction ### permutations Pseudo-code Keccak-f 將會跑n輪 n是依照permutation的寬度決定 n=12+2l 2^l = w 若w=64 則l=6 就會跑n=12+12 n=24輪 對資料進行多種的變化 XOR r[x,y] rotation offsets RC[i] round constants rot(W,r) bitwise cyclic shift operation,moving bit at position i into position i+r 透過θ、ρ、π、χ、ι 五個函式完成排列置換 ![](https://i.imgur.com/8qGO2BD.png) https://keccak.team/keccak_specs_summary.html https://ithelp.ithome.com.tw/articles/10242611 https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf