# Tag Info

## New answers tagged sha256

1

No, it is not possible to get exactly equal probabilities for a deterministic mapping from all 256-bit numbers to the range 0-99. However, you can ask whether it matters, since a bias on the order of $2^{-256}$ is undetectable. A mapping that took the 256-bit number modulo 100 and refused the inputs less than $2^{256} \bmod 100$ would be unbiased and would ...

5

I agree with the comments that SHA-256 should be fine here. However, if you already use HMAC-SHA-256 for PBKDF2, you could use HKDF Expand, which despite its name is defined even for output lengths shorter than input. In your case the output would be simply: $$\operatorname{HMAC-SHA-256}(\text{key}, \text{info} || \text{0x01}),$$ where 'info' is an ...

-1

You could simply just XOR all the bytes of the hash to one single byte (lets call it $b$ for now): $b = hash_0 \oplus hash_1 \oplus ... \oplus hash_{31}$. $b \in [0, 255]$. Calculate $b' = b / 2.55$. $b' \in [0, 100]$.

7

If you mean exactly as likely, no, because the number of possible hashes is not a multiple of $100$. This is assuming all the hashes are exactly equally likely. You can come very close just by taking $SHA256 hash \pmod {100}$ This will be within one part in $\frac {2^{256}}{100}$, which is a very small number. If you want truly equal, check that the hash ...

0

All the arithmetic in SHA-256 should be 32-bit, it can be implemented at a low level using only 32-bit registers. If you use a representation that can go over 32 bits, then you need to truncate back to 32 bits on every calculation in your chosen language where it will not do so itself - i.e. on every addition.

0

Please review how message authentication codes and HMAC work. They are covered in standard resources (e.g., Wikipedia, crypto textbooks, search on this site). They are just saying that Hashlet can be used to compute a HMAC, which indeed does not encrypt; it provides message authentication.

2

Theoretically, a hash function can be insecure and leak information about the plaintext. In this case knowing multiple hashes will let you make use of weaknesses in any of them. I agree with Dmitry Khovratovich that this isn't likely if you choose hash functions that are considered good, but it is a possibility. More concretely, knowing multiple hash ...

2

No, there is no security decrease in this case. While there could be some hypothetical constructions that might leak the preimage if two images are known, this is definitely not the case for existing hash functions, which are all quite different from each other. An example of such a weak pair of hash functions could be two versions of MD5: one with 63 ...

6

It is possible to turn a hash function into a stream cipher; there are several methods for that, and the simplest is to compute $h(K||IV||x)$ for hash function $h$, initialization vector $IV$, and successive values of a counter $x$. This yields an arbitrarily long sequence of pseudo-random blocks (32 bytes per invocation if $h$ is SHA-256). Then XOR that ...

4

From RFC 5246, section 6.2.3.3: AEAD Ciphers: AEAD ciphers take as input a single key, a nonce, a plaintext, and "additional data" to be included in the authentication check, as described in Section 2.1 of [AEAD]. The key is either the client_write_key or the server_write_key. No MAC key is used. However in RFC 5246, section 5: HMAC ...

Top 50 recent answers are included