1

Linux カーネルで Crypto API (MD5) を使用しています。「動作中」ですが、正しく動作しているかどうかはわかりません。テストとして、次の文字列を例として使用しています。

Here is a completely different setup that should produce a different fingerprint. Let's see.    

結果のハッシュは

534d78034b774b6266f2189576f8c6e3

スジは通ってるようだ。そこで、オンライン サイトhttp://www.sha1-online.com/をチェックして、結果を確認します。

07a90df929448eb67b00a6e01a202519

明らかに間違っています。これが私のコードです:

static int fingerprint(void)
{
  struct scatterlist sg;
  struct crypto_hash *tfm;
  struct hash_desc desc;
  unsigned char * output;
  unsigned char * buf;
  int i;

  output = kmalloc(sizeof(*output) * 16, GFP_KERNEL);
  memset(output, 0x00, 16);

  buf = "Here is a completely different setup that should produce a different fingerprint. Let's see.";

  tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);

  desc.tfm = tfm;
  desc.flags = 0;

  sg_init_one(&sg, buf, 92);
  crypto_hash_init(&desc);

  crypto_hash_update(&desc, &sg, 92);
  crypto_hash_final(&desc, output);

  for(i = 0; i < 16; i++)
  {
    printk("%02x", output[i]);
  }

  printk("\n"); 
  return 0;
}

このコードは正しいですか?問題はありますか (明白または微妙)。

4

0 に答える 0