shabal192.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* shabal192.c */
  2. /*
  3. This file is part of the ARM-Crypto-Lib.
  4. Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /*
  17. * \file shabal192.c
  18. * \author Daniel Otte
  19. * \email daniel.otte@rub.de
  20. * \date 2009-04-27
  21. * \license GPLv3 or later
  22. *
  23. */
  24. #include <stdint.h>
  25. #include <crypto/shabal.h>
  26. #include <string.h>
  27. const uint32_t shabal192_iv[] = {
  28. /* A */
  29. 0xFD749ED4, 0xB798E530, 0x33904B6F, 0x46BDA85E,
  30. 0x076934B4, 0x454B4058, 0x77F74527, 0xFB4CF465,
  31. 0x62931DA9, 0xE778C8DB, 0x22B3998E, 0xAC15CFB9,
  32. /* B */
  33. 0x58BCBAC4, 0xEC47A08E, 0xAEE933B2, 0xDFCBC824,
  34. 0xA7944804, 0xBF65BDB0, 0x5A9D4502, 0x59979AF7,
  35. 0xC5CEA54E, 0x4B6B8150, 0x16E71909, 0x7D632319,
  36. 0x930573A0, 0xF34C63D1, 0xCAF914B4, 0xFDD6612C,
  37. /* C */
  38. 0x61550878, 0x89EF2B75, 0xA1660C46, 0x7EF3855B,
  39. 0x7297B58C, 0x1BC67793, 0x7FB1C723, 0xB66FC640,
  40. 0x1A48B71C, 0xF0976D17, 0x088CE80A, 0xA454EDF3,
  41. 0x1C096BF4, 0xAC76224B, 0x5215781C, 0xCD5D2669
  42. };
  43. void shabal192_init(shabal_ctx_t* ctx){
  44. uint8_t i;
  45. ctx->b = ctx->b_buffer;
  46. ctx->c = ctx->c_buffer;
  47. ctx->w.w64 = 1LL;
  48. for(i=0;i<SHABAL_R;++i){
  49. ctx->a[i] = shabal192_iv[i];
  50. }
  51. for(i=0;i<16;++i){
  52. ctx->b[i] = shabal192_iv[SHABAL_R+i];
  53. }
  54. for(i=0;i<16;++i){
  55. ctx->c[i] = shabal192_iv[SHABAL_R+16+i];
  56. }
  57. }
  58. void shabal192_ctx2hash(void* dest, const shabal_ctx_t* ctx){
  59. shabal_ctx2hash(dest, ctx, 192);
  60. }
  61. void shabal192(void* dest, void* msg, uint32_t length_b){
  62. shabal_ctx_t ctx;
  63. shabal192_init(&ctx);
  64. while(length_b>=SHABAL_BLOCKSIZE){
  65. shabal_nextBlock(&ctx, msg);
  66. msg = (uint8_t*)msg+SHABAL_BLOCKSIZE_B;
  67. length_b -= SHABAL_BLOCKSIZE;
  68. }
  69. shabal_lastBlock(&ctx, msg, length_b);
  70. shabal192_ctx2hash(dest, &ctx);
  71. }