md5.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Cryptographic API.
  3. *
  4. * MD5 Message Digest Algorithm (RFC1321).
  5. *
  6. * Adapted for OCTEON by Aaro Koskinen <aaro.koskinen@iki.fi>.
  7. *
  8. * Based on crypto/md5.c, which is:
  9. *
  10. * Derived from cryptoapi implementation, originally based on the
  11. * public domain implementation written by Colin Plumb in 1993.
  12. *
  13. * Copyright (c) Cryptoapi developers.
  14. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License as published by the Free
  18. * Software Foundation; either version 2 of the License, or (at your option)
  19. * any later version.
  20. */
  21. #include <asm/octeon/crypto.h>
  22. #include <asm/octeon/octeon.h>
  23. /*
  24. * We pass everything as 64-bit. OCTEON can handle misaligned data.
  25. */
  26. static void md5_blocks(struct md5_block_state *state,
  27. const u8 *data, size_t nblocks)
  28. {
  29. struct octeon_cop2_state cop2_state;
  30. u64 *state64 = (u64 *)state;
  31. unsigned long flags;
  32. if (!octeon_has_crypto())
  33. return md5_blocks_generic(state, data, nblocks);
  34. cpu_to_le32_array(state->h, ARRAY_SIZE(state->h));
  35. flags = octeon_crypto_enable(&cop2_state);
  36. write_octeon_64bit_hash_dword(state64[0], 0);
  37. write_octeon_64bit_hash_dword(state64[1], 1);
  38. do {
  39. const u64 *block = (const u64 *)data;
  40. write_octeon_64bit_block_dword(block[0], 0);
  41. write_octeon_64bit_block_dword(block[1], 1);
  42. write_octeon_64bit_block_dword(block[2], 2);
  43. write_octeon_64bit_block_dword(block[3], 3);
  44. write_octeon_64bit_block_dword(block[4], 4);
  45. write_octeon_64bit_block_dword(block[5], 5);
  46. write_octeon_64bit_block_dword(block[6], 6);
  47. octeon_md5_start(block[7]);
  48. data += MD5_BLOCK_SIZE;
  49. } while (--nblocks);
  50. state64[0] = read_octeon_64bit_hash_dword(0);
  51. state64[1] = read_octeon_64bit_hash_dword(1);
  52. octeon_crypto_disable(&cop2_state, flags);
  53. le32_to_cpu_array(state->h, ARRAY_SIZE(state->h));
  54. }