0

Assume that we have (know):

  1. Hash(A)
  2. Length of A
  3. A's character type ([0->9],[a->z])
  4. A is a string
  5. Everything about B (original string, Length, etc.)
  6. HashMethod SHA256
  7. Note: A's original value is unknown

Is there a way to use that information to create Hash(A||B) [|| is concatenate {"a" || "b" -> "ab" for example}]

  • similar question here https://crypto.stackexchange.com/questions/34795/can-i-compute-sha256secretdata-when-having-sha256secret-and-data?rq=1 – lamba Jul 03 '22 at 08:07

2 Answers2

4

Is there a way to use that information to create Hash(A||B)

No, it is not. However, we can come close: we can compute Hash(A||PadA||B), where PadA is a string that depends on the length of A (but not on its contents). This is known as the 'length extension attack' on SHA256.

poncho
  • 147,019
  • 11
  • 229
  • 360
  • Thanks for your reply, I have a further question: What you do mean by "come close", I thought it is "Right or Wrong" matter – Hoi Nhon Nguyen Jun 30 '22 at 14:12
  • @HoiNhonNguyen: "come close" means "you can't do exactly what you ask, however by tweaking the problem a little, you can solve the tweaked problem" – poncho Jun 30 '22 at 14:53
  • Apart from "Length extension attack" is there any other method to be considered? – Hoi Nhon Nguyen Jun 30 '22 at 16:01
  • @HoiNhonNguyen: well, if the length of A is not too large, you could use a brute force (or rainbow table) to recover it; once you know A, computing Hash(A||B) is easy... – poncho Jun 30 '22 at 17:30
0

If the output needs to be a SHA256 digest then there's not much you can do except what is mentioned by @poncho. But if you want to use SHA256 in a Merkle tree then you can chunk A up into small pieces and make a Merkle root out of it, this is your Hash(A). When B is available you do the same. Finally, you hash those two Merkle roots together to create Hash(A||B). Of course, the length of A and B should be the same ideally.

lamba
  • 1,365
  • 8
  • 18