gf256mul.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* gf256mul.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. #include <stdint.h>
  17. uint8_t gf256mul(uint8_t a, uint8_t b, uint8_t reducer){
  18. uint8_t r=0;
  19. while(a&0xFE){
  20. if(a&1){
  21. r ^= b;
  22. }
  23. a >>= 1;
  24. if(b&0x80){
  25. b <<= 1;
  26. b ^= reducer;
  27. }else{
  28. b <<= 1;
  29. }
  30. }
  31. if(a&1){
  32. r ^= b;
  33. }
  34. return r;
  35. }