⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme_crypto

📁 shs加密源程序
💻
字号:
	Notes on hash based symmetric encryption and signatures	by Michael Graffam (mgraffam@mhv.net)The theory of a hash based cipher is a simple one: grab a key fromthe user and use this as the initial input to the hash algorithm,the output values are treated as random numbers to be xor'd withthe plaintext. Just what we do when we run out of pseudo-random bits is the interestingpart. The simplest solution, of course is to simply roll back to thebeginning of the hash and keep encrypting.. this method yields aglorified and still completely insecure Vigenere cipher.A more cryptographically sound method is to simply throw the hash valuesthat we had been using back into the one-way function and get somenew bits. While this method is safe against ciphertext-only attacks(unlike the previous method), it is still vulnerable to a knownplaintext attack. If the attacker knows N bits of plaintext (whereN is the length of the digest), then he easily compute what hashwas used. While he cannot use this hash to get previous bits ofplaintext, all plaintext from that section onward can be read, andperhaps more importantly, the attacker can change the plaintextsuch that upon decryption the message is different (and stillmeaningful). Obtaining new random bits by hashing the original key and the oldhash solves the problem of a known plaintext attack, but there isstill one cryptanalytic attack to be overcome.Hashing a key, and then hashing the hash+key will always generatethe same random number stream regardless of the plaintext beingencrypted. From a cryptanalytic point of view we can treat anencryption system based on this stream like a one-time pad thathas been used twice.What we need is a random number stream that is affected by theplaintext values so that even if the same user key is used on two different messages the random bits used to encrypt themessages will be different. Therefore, we use the followingalgorithm:	HASH(User_key) -> H     +->H xor Plaintext_block -> Ciphertext_block     |  HASH(User_key + Plaintext_block + H) -> H     |  Get new Plaintext_block     |  |     +--+If the attacker knows the very first plaintext block, he can calculate the hash that it was xor'd against. But he cannot usethis information to get the user's key (because it is a one-wayfunction) and he cannot get subsequent plaintexts because he wouldneed the user's key to calculate the next hash value, thereforethe system is secure.All that having been said, if you need to keep something private,and you want to use a symmetric key cipher, use IDEA or Blowfish.Hash functions are not really meant to be used in this fashion,and will be slower than an algorithm like IDEA. There is alsothe problem that hash functions are generally not designed tobe used as a source of random numbers, they are designed to givea digest of an arbitrary length input. It could very well be thata hash function used in the manner described above might exposecharacteristics to cryptanalytic attack that would not ordinarilybe a problem when used in the manner it was designed for.. this isunlikely to be a problem, in my opinion, but it is something tothink about.Not to mention. It's slow ;) So why did I take the time to write up a cipher based on this? Well,I was bored, and I wanted to learn about SHA so I started playingwith the source and started reading the relevant portions in Handbookof Applied Cryptography. But there are some very practical purposesfor designing such ciphers and exploring their properties.One, unfortunately very real, use is in the area of export regulations.It is not illegal to export a hash function but it is illegal toexport a cipher in some countries (you get three guesses to name acountry, the first 2 don't count). By making ciphers based on hashfunctions source code could be split into two parts, a random numbergeneration part and code to XOR bytes together. Both of these packagesshould then be able to be exported and simply compiled together withno legal troubles.Another, more practical area of use would be in low memory situationswhere both hashing and crypto are required. It could be overly expensiveto have two algorithms sitting around; use of one algorithm for bothapplications might be needed. Symmetric signatures are another matter entirely. It works like this:to sign a document one simply prepends a secret key and hashes thenew document. This message digest is your signature for the originalmessage. For someone to verify that you signed the document he checkslike we would in real life: he asks you to sign it and compares thesignatures.Of course, you can repudiate your signature at any time. If someonewants you to sign the document, and you don't want them to knowthat you signed it you simply don't use the correct key. Such asystem is useful in an environment where you would like to proveto Winston that you signed a document, and are thus his ally, butdon't want to be held accountable for that signature when yougo over to the Ministry of Love to have tea and talk over yourpolitical views.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -