Hash Tree

Hash Tree

社内LT大会 0x64物語 #02 Data Structure 資料

3f1b3c7b051241022d973fff2e713c1b?s=128

HORINOUCHI Masato

November 10, 2015
Tweet

Transcript

  1. Hash Tree 2015/11/10 0x64 Tales #02 Data Structure Livesense Inc.

    HORINOUCHI Masato
  2. Hash Tree ͬͯͳʹ?

  3. ֓ཁ ҉߸ཧ࿦͓ΑͼܭࢉػՊֶʹ͓͍ͯɺϋογϡ໦(Hash tree, ϋο γϡπϦʔ)·ͨ͸ϚʔΫϧ໦(Merkle tree)ͱ͸ɺΑΓେ͖ͳσʔ λʢྫ͑͹ϑΝΠϧʣͷཁ໿݁ՌΛ֨ೲ͢Δ໦ߏ଄ͷҰछͰ͋ ΓɺσʔλͷݕূΛߦ͏ࡍʹ࢖༻͞ΕΔɻ — ϋογϡ໦

    - Wikipedia
  4. ཁ͢Δʹ… େ͖ͳσʔλΛෳ਺σʔλϒϩοΫ ʹ෼ׂ͠ɺഁଛ΍վ᜵ͷݕূॲཧʹ ར༻Ͱ͖Δɻ

  5. ಈ࡞ݪཧ • ೋ෼໦ • Ϧʔϑ • σʔλϒϩοΫͷϋογϡ஋ • (಺෦)ϊʔυ •

    ࢠϊʔυͷϋογϡ஋Λ݁߹ͨ݁͠Ռͷϋογϡ஋
  6. None
  7. σϞ ݩσʔλੜ੒ $ dd if=/dev/urandom of=sample bs=1M count=4 $ split

    --bytes=1048576 --numeric=1 --suffix-length=1 sample L $ ls -l -rw-r--r-- 1 horinouchi horinouchi 1048576 Nov 10 18:37 L1 -rw-r--r-- 1 horinouchi horinouchi 1048576 Nov 10 18:37 L2 -rw-r--r-- 1 horinouchi horinouchi 1048576 Nov 10 18:37 L3 -rw-r--r-- 1 horinouchi horinouchi 1048576 Nov 10 18:37 L4 -rw-r--r-- 1 horinouchi horinouchi 4194304 Nov 10 18:34 sample σʔλݕূͳͲͰར༻͢ΔMerkle TreeͷϝϞ Λࢀߟʹ͠·ͨ͠ɻ
  8. ख࡞ۀ $ openssl dgst -sha256 -binary L1 > H00 $

    openssl dgst -sha256 -binary L2 > H01 $ openssl dgst -sha256 -binary L3 > H10 $ openssl dgst -sha256 -binary L4 > H11 $ cat H00 H01 | openssl dgst -sha256 -binary > H0 $ cat H10 H11 | openssl dgst -sha256 -binary > H1 $ cat H0 H1 | openssl dgst -sha256 -binary > TOP $ hexdump -C TOP
  9. Ruby gem $ gem install treehash $ treehash sample •

    Treehash • ͱ͸͍͑ɺ͜ͷ gem ͷத਎͸શ͘ೋ෼໦࢖ͬͯͳ͍…ɻ
  10. ZFS • Data integrity (σʔλ׬શੑ) • σΟεΫΛ௚઀ॻ͖׵͑ͯ΋ϒϩοΫ୯ҐͰνΣοΫͰ͖Δ Αɻ • Copy-On-Write

    • ϒϩοΫ୯ҐͰߋ৽ՕॴͷΈ write Ͱ͖ΔΑɻ
  11. ଞͷ Hash Tree ͷར༻ • P2P • BitTorrent • Bitcoin

    • ෼ࢄVCS • Git
  12. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠