Ballonen
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: "SHA256" author: "Barger Maximilian, Kofler Lorenz" date: May 31, 2021 fontsize: 9pt institute: "SIB18: KYP" colortheme: "dolphin" theme: "Berlin" classoption: "aspectratio=169" mainfont: DejaVuSerif.ttf sansfont: DejaVuSans.ttf monofont: DejaVuSansMono.ttf mathfont: texgyredejavu-math.otf output: beamer_presentation: keep_tex: true includes: in_header: columns.tex --- # Teilaufgabe 2 ```python def authenticate_message(message, key): return message + hashlib.sha256(key + message).digest() ``` ``` 00000000: 3031 3145 4861 6c6c 6f20 416e 6e61 2120 011EHallo Anna! 00000010: 4175 6667 7275 6e64 2065 696e 6573 2053 Aufgrund eines S 00000020: 6963 6865 7268 6569 7473 766f 7266 616c icherheitsvorfal 00000030: 6c73 2073 696e 6420 616c 6c65 2045 2d4d ls sind alle E-M [...] 000000d0: 2046 6f6c 6765 6e64 6520 4b65 792d 4944 Folgende Key-ID 000000e0: 7320 7369 6e64 2065 726c 6175 6274 3a20 s sind erlaubt: 000000f0: 3645 3839 3344 4232 2c20 3146 3338 4133 6E893DB2, 1F38A3 00000100: 3030 eda5 6147 ccd7 a18b 09e2 0e5e b818 00..aG.......^.. 00000110: b8ee 2c16 1609 8bf0 a502 3c29 9d27 428d ..,.......<).'B. 00000120: 36de 6. ``` # Merkle-Damgård-Konstruktion - Nachricht wird in Blöcke (SHA256: 512 Bit) - Padding wird angehängt wenn nötig - f: Kompressionsfunktion - 2 Inputs - Message Block - IV ```clike Message Message Message Length Block 1 Block 2 Block n Padding +------+ | | | | +-----+ +------+ | | +---+ +---+ +---+ +---+ | | | | | IV | ══> | f | ══> | f | ... ══> | f | ══> | f | ══> | Fin | ══> | Hash | | | +---+ +---+ +---+ +---+ | | | | +------+ +-----+ +------+ `````` # Padding ```clike SHA256-Padding (skaliert um Faktor 16 --> 32 Bit Blöcke) Nutzdaten: +--------------------------------+ |1001100011010 | ╔══ +--------------------------------+ ║ ║ Anfügen des '1'-Bits ╚══>+-------------↓------------------+ |10011000110101 | ╔══ +-------------↑------------------+ ║ ║ Auffüllen mit '0'-Bits Originallänge der Daten (13 Bit) ╚══>+--------------↓↓↓↓↓↓↓↓↓↓↓↓↓↓----+ +----------------------------↓↓↓↓+ |1001100011010100000000000000 | ══> |10011000110101000000000000001101| +--------------↑↑↑↑↑↑↑↑↑↑↑↑↑↑----+ +----------------------------↑↑↑↑+ ``` # Length Extension Attack - HMAC: Integritätsschutz mithilfe eines secret keys ```python hmac = hash(key || message) data = message || hmac ``` - Merkle-Damgård-Konstruktion - Blöcke werden einzeln verarbeitet - Nach jedem Block ein fixer Zwischen-State - Vorherige Blöcke müssen nicht bekannt sein --> Key nur bei Block #0 relevant - Hash wird über Daten inklusive Padding berechnet - Ziel: Daten verlängern und dazu eine validen HMAC erstellen ```python hmac = hash(key || message || paddding || new_message) ``` # Teilaufgabe 3: Analyse des Codes ```python def sign_message(message, key): if len(key) / 32 >= len(message) * 2: # key >= 64 * len(message) for i, mc in enumerate(message): # i ... character position # mc ... ascii character in decimal for j, part in enumerate(divmod(mc, 16)): # (div, mod) = divmod() # j ... index (0, 1) # part ... div (index == 0), mod (index == 1) signature = key[(i*2+j)*32:(i*2+j+1)*32] # signatur = X-te 32 Byte Word aus dem Key for _ in range(part): # Hasht den key div/mod-mal (je nach index) # --> 2 Signaturen pro Message Byte signature = hashlib.sha256(signature).digest() message = message + signature return message else: return None ``` # Signaturerstellung - Anzahl der Hash Cycles wird durch division und modulo bestimmt - Jeder Character beeinflusst 2 Hashes: - ```DIV HASH``` - ```MOD HASH``` - Maximale Anzahl an Hash Cycles = 15 (weil divmod(mc,16)) # Angriff auf das "Signatur"-Verfahren 1/2 - Verändern von ```Be``` --> ```lo``` ``` |DIV HASH |MOD HASH| chr | dec | dec//16 | dec%16 | ============================== B | 66 | 4 | 2 | e | 101 | 6 | 5 | ============================== l | 108 | 6 | 12 | o | 111 | 6 | 15 | ``` - Es ist nur möglich sich in der Hash-Chain nach vorne zu bewegen # Angriff auf das "Signatur"-Verfahren 2/2 ```python ╔══════════════════════╗ b'Hallo Anna! Wir haben einen neuen Mitarbeiter namens "Beda",' ║ Old Message ║ b'seine E-Mail-Adresse lautet P00000000000000@beda.fh-hagenberg.at.' ╚══════════════════════╝ b'Lg, Hannes' ╔══════════════════════╗ b'Hallo Anna! Wir haben einen neuen Mitarbeiter namens "loma",' ║ New Message ║ b'seine E-Mail-Adresse lautet maxi_lorenz@students.fh-hagenberg.at.' ╚══════════════════════╝ b'Lg, Hannes' ``` ``` | chr | div | mod | DIV HASH | MOD HASH | OLD | B | 4 | 2 | d44c[...]b529 | 45be[...]02f1 | | ⇩ | ⇩ | ⇩ | | ⇩ | HashCycles: 2 | HashCycles:10 | | ⇩ | ⇩ | ⇩ | NEW | l | 6 | 12 | 4ec3[...]9acd | 7b53[...]f95a | | chr | div | mod | DIV HASH | MOD HASH | OLD | e | 6 | 5 | 5fe5[...]fb60 | 3887[...]3fd2 | NEW | o | 6 | 15 | 5fe5[...]fb60 | d73a[...]4108 | ``` # Einmalsignaturverfahren ```{=latex} \begin{columns} \begin{column}{0.5\textwidth} ``` - Einmalsignatur: für jeden Public Key nur eine einzige Signatur - Winternitz OTS (WOTS) - Anzahl der Hash Cycles ist abhängig von der Message ```{=latex} \vspace{32pt} ``` - Angriff verhindern: - Checksum und Checksum-Signatur anhängen ```{=latex} \end{column} \begin{column}{0.5\textwidth} ``` ```python +-------------------+ | pubkey = h(sig) | +-------------------+ ⇧ +---------------+ | sig = h(h(p)) | <- Hash Cycles abhängig +---------------+ von Message ⇧ +---+ | p | <- Private Key +---+ ``` ```{=latex} \end{column} \end{columns} ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully