Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SHA256の実装を pythonで読むために
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yusuke Egami
March 17, 2018
Technology
770
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SHA256の実装を pythonで読むために
Yusuke Egami
March 17, 2018
More Decks by Yusuke Egami
See All by Yusuke Egami
MasteringBitcoin 第5章トランザクション
egapool
3
520
Bitcoinオフチェーン入門_ビットコインとか勉強会#23
egapool
4
1.3k
Segregate Witness (bitcoin) #blockchainkyoto
egapool
1
290
単方向マイクロペイメントチャネル(ビットコイン)
egapool
0
290
bitcoinトランザクション総復習 #blockchainkyoto
egapool
1
350
Other Decks in Technology
See All in Technology
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
730
go-sqletch
moznion
0
140
Loop Engineering, beyond prompt, context, and harness engineering
glaforge
0
110
遠藤な_めぐろLT #38 「社内のAI活用推進」@麻布台_20261009
endonanana
0
130
How to Design Configuration for Rails Applications
willnet
0
430
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
210
事業成長とデータ活用を止めないためのマネジメントへ挑戦
hiracky16
0
340
宣言型部分更新は何を解決しどこへ向かうのか
shuta13
1
390
Post AI時代のリファクタリング実践記 / Refactoring in the post AI era
kaminashi
1
210
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
280
Claude Code本は、どのように執筆チームで書かれたか
oikon48
1
370
AI時代のPRレビューにどう向き合うか?
kairim0
1
230
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
320
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
Building the Perfect Custom Keyboard
takai
2
900
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
320
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
730
Between Models and Reality
mayunak
4
490
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Transcript
SHA256ͷ࣮Λ pythonͰಡΉͨΊʹ ΜͳΓpython#4(20180316) ΤΨϛ Ϣεέ @egapool
SHA256ͷ͓͞Β͍
SHA256ͱ ҉߸ֶతϋογϡؔͷSHA-2γϦʔζͷҰ ͭ SHA-224ɺSHA-256ɺSHA-384ɺSHA-512
ϋογϡؔͱ ͋Δσʔλ͔ΒཁʢࢦͷΑ͏ͳͷʣΛ ಘΔؔ
҉߸ֶతϋογϡؔͱ ϋογϡؔʹҎԼ͕Ճ͞Εͨͷ ɾҰํੑ ɹᵋϋογϡΛ͔ΒݩͷϝοηʔδΛਪଌͰ͖ͳ͍ ɾিಥੑ ɹᵋ ಉ͡ϋογϡΛੜ͢ΔϝοηʔδͷϖΞΛݟ͚ͭΔ͜ ͱ͕ࠔ
SHA256ͷ࣮ͷհ
༷FIPS 180-2Ͱެ։ ΞϝϦΧࠃཱඪ४ٕज़ݚڀॴ (NIST) ͕ൃߦ https://csrc.nist.gov/csrc/media/ publications/fips/180/2/archive/ 2002-08-01/documents/fips180-2.pdf
hashlibϞδϡʔϧ hashlibͰsha256ͷ࣮cpython࣮ͷϞδϡʔϧΛimport͍ͯ͠ Δ [hashlib] https://github.com/python/cpython/blob/3.6/Lib/hashlib.py#L89-L92 [_sha256] https://github.com/python/cpython/blob/3.6/Modules/ sha256module.c
nanvel/sha256.py https://gist.github.com/nanvel/ 9e606cb7271126b1cb2413b7415d560d
SHA256ͷΞϧΰϦζϜ
SHA256࠷ऴతʹ256bit(=32byte)ͷจࣈྻΛు ͖ग़͢ ༷Ͱॳظ͕༩͑ΒΕ͍ͯΔ 6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab
5be0cd19 (4byte x 8ݸ) ͜ͷॳظΛมԽ͍ͤͯ͘͞
͓͓·͔ͳྲྀΕ 1. ϝοηʔδΛ64byte͝ͱͷϒϩοΫʹׂ 2. ύσΟϯάॲཧ 3. લஈͷϋογϡͱϒϩοΫʹରͯ͠64ճͷϥϯ υॲཧΛͯ͠32byteͷϋογϡΛಘΔ 4. 3
ΛશϒϩοΫճ͢
ɾɾɾ ϥϯυ ϥϯυ ॳظ CZUF ϋογϡ CZUF ϋογϡ CZUF ࠷ऴతͳϋογϡ
CZUF ͓͓·͔ͳྲྀΕ ϥϯυ
ύσΟϯάॲཧ w ϝοηʔδΛCZUFͰׂͬͨ࠷ޙͷϒϩοΫʹదԠ w CZUFʹΒͳ͍͚ͩͰຒΊΔ w ͨͩ͠ɺͱϝοηʔδͷ࠷ޙʹCJUΛՃ w ͞ΒʹɺCZUFͷඌʹCZUFจͷͱϝοηʔδ Λ͍ΕΔ
w ݩʑ͖ͬͪΓCZUFͩͬͨ߹͞ΒʹϒϩοΫΛ Ճͯ͠ɺͦΕʹରͯ͠ύσΟϯάॲཧΛࢪ͢
ύσΟϯάॲཧ CZUFͷϝοηʔδͷ߹ ˞ਐͰਐͰ ˞CZUFCJUɺਐͰ BCBCDEDEFGFGBCBCDEDEFGFG BCBCDEDEFGFG BCBCDEDEFGFGBCBCDEDEFGFG BCBCDEDEFGFG
ϥϯυ w CZUFͷϒϩοΫΛCZUFʹ֦ுͯ͠ݸºCZUF Λੜ w ˢͱఆΛͬͯճͷϩʔςʔγϣϯॲཧతͳͷ Λࢪ͢
ϥϯυ CZUFͷϒϩοΫΛCZUFʹ֦ுͯ͠ݸºCZUF Λੜ ɾɾ
ɾɾ
w = [0] * 64 w[0:16] = to_chunks(chunk, n=32) for
i in range(16, 64): s0 = bin_xor(bin_rrot(w[i-15], 7), bin_rrot(w[i-15], 18), bin_rshift(w[i-15], 3)) s1 = bin_xor(bin_rrot(w[i-2], 17), bin_rrot(w[i-2], 19), bin_rshift(w[i-2], 10)) w[i] = bin_sum( w[i-16], s0, w[i-7], s1 ) IUUQTHJTUHJUIVCDPNOBOWFMFDCCDCCEEpMFTIBQZ-- ϥϯυ CZUFͷϒϩοΫΛCZUFʹ֦ுͯ͠ݸºCZUF Λੜ
ϥϯυ ˠͱˠͰมԽ ϥϯυॲཧ
GPSJJOSBOHF TVNCJO@TVN X<J> JOU@UP@MJTU @L<J>
I CJO@DI F G H CJO@YPS CJO@SSPU F CJO@SSPU F CJO@SSPU F TVNCJO@TVN CJO@YPS CJO@SSPU B CJO@SSPU B CJO@SSPU B CJO@NBK B C D TVN B C D E F G H ITVN B C D CJO@TVN E TVN <> F G H ॳظఆ
IUUQTDTSDOJTUHPWDTSDNFEJBQVCMJDBUJPOTpQTBSDIJWFEPDVNFOUTpQTQEG ϥϯυΛܦΔʹมԽ͍ͯ͘͠ ϥϯυ '*14ͷʹʮBCDʯͱ͍͏จࣈΛ4)"ͰϋογϡԽ͢ Δ༷ࢠ͕հ͞Ε͍ͯΔ
ӈγϑτԋࢉ ᵋࢉज़ՃࢉͰͷ্͚͕ͨΓʢ"EEJUJPOʣ ८ճӈγϑτԋࢉ ᵋ८ճϏοτγϑτԋࢉʢ3PUBUJPOʣ ഉଞతཧ ᵋഉଞతཧʢ903ʣ ARXܕ ೖྗʹରͯ͠ඇઢܗͳ݁ՌΛಘΔͨΊͷউͪύλʔϯ
͓͠·͍