Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| efinf:blcks2017:crypto:start [2017/12/14 07:55] – [Anwendung BadBlockChain] Ivo Blöchliger | efinf:blcks2017:crypto:start [2017/12/20 21:08] (current) – [Theorie] Ivo Blöchliger | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== News ===== | ||
| + | * https:// | ||
| + | ===== Theorie ===== | ||
| + | * Hashfunktion: | ||
| + | * Asymmetrische Kryptographie: | ||
| + | * Public-Key Verschlüsselung: | ||
| + | * RSA-Verschlüsselung: | ||
| + | * Blockchain: https:// | ||
| + | ===== BadBlockChain ===== | ||
| + | {{ : | ||
| + | |||
| + | |||
| + | ==== Format eines BadBlocks ==== | ||
| + | <code txt> | ||
| + | 5 # Nummer des Blocks | ||
| + | 98 # Hash vom Vorgängerblock | ||
| + | 1 # Anzahl Transactions | ||
| + | 1513199769622, | ||
| + | 8565935687, | ||
| + | </ | ||
| + | |||
| + | ==== Transaction ==== | ||
| + | <code txt> | ||
| + | 1513199769622, | ||
| + | </ | ||
| + | Timestamp (ms seit 1.1.1970), | ||
| + | Public Key vom Sender, | ||
| + | Public Key vom Empfänger, | ||
| + | Betrag der überwiesen wird, | ||
| + | Digitale Unterschrift vom Sender | ||
| + | |||
| + | === Unterschrift === | ||
| + | Man bildet den Hash $h$ der Transaction (ohne ', | ||
| + | $h$ wird mit PrivateKey vom Sender verschlüsselt. | ||
| + | |||
| + | Verfizierung: | ||
| + | |||
| + | ==== RSA ==== | ||
| + | Sei n eine Zahl, der Modulus. | ||
| + | |||
| + | Rechnen mit Resten modulo n: Alle Resultate werden durch n geteilt und der Rest genommen. | ||
| + | |||
| + | $a^x \mod n = b$ kann nicht effizient nach $x$ aufgelöst werden, d.h. der diskrete Logarithmus ist nicht effizient berechenbar. | ||
| + | |||
| + | RSA: öffentlicher Modulus $m$, öffentlicher Exponent $e$, privater Exponent $p$. | ||
| + | |||
| + | Clou: $\left(a^e\right)^p = a = \left(a^p\right)^e = a^{e\cdot p} \mod m$. | ||
| + | |||
| + | ===== Anwendung BadBlockChain ===== | ||
| + | === Key Management === | ||
| + | Key Erzeugen: | ||
| + | <code python makekey.py> | ||
| + | from badkeymaterial import BadKeyMaterial | ||
| + | |||
| + | print BadKeyMaterial(32) | ||
| + | </ | ||
| + | Ausgabe z.B. | ||
| + | Public modulus: 4906493971 public exponent: 31 private exponent: 158269471 | ||
| + | Key verwenden: | ||
| + | <code python initkey.py> | ||
| + | from badkeymaterial import BadKeyMaterial | ||
| + | |||
| + | # modulus eintragen | ||
| + | k=BadKeyMaterial(4906493971) | ||
| + | # privaten Schlüssel setzen | ||
| + | k.private = 158269471 | ||
| + | |||
| + | </ | ||
| + | |||
| + | Mining: | ||
| + | <code python miner.py> | ||
| + | from badblockchain import BadBlockChain | ||
| + | from badkeymaterial import BadKeyMaterial | ||
| + | |||
| + | c = BadBlockChain() | ||
| + | c.getNewBlocks() | ||
| + | |||
| + | # modulus eintragen | ||
| + | k=BadKeyMaterial(4906493971) | ||
| + | # privaten Schlüssel setzen | ||
| + | k.private = 158269471 | ||
| + | |||
| + | c.mine(k.modulus) | ||
| + | |||
| + | print c.wallets.wallets | ||
| + | |||
| + | </ | ||
| + | |||
| + | Neue Hash-Funktion: | ||
| + | <code python> | ||
| + | # 32-Bit Hash | ||
| + | @classmethod | ||
| + | def badHash(cls, | ||
| + | x = str(x) | ||
| + | h = 0xdeadbeef | ||
| + | for i in xrange(0, | ||
| + | h = ((h+6543)*(ord(x[i])+57361)+567) % 2**32 | ||
| + | return h | ||
| + | |||
| + | </ | ||