免费做A爰片久久毛片A片下载_中文欧美三级精品_免费一级少妇A片无码专区_日韩亚洲三级片在线视频_国产熟女Aa级毛片_无码亚中文字幕2021_亚洲国产精品不卡在线观看_成人欧美一区二区三区1314_日本午夜精品理论片a级_337p日本欧洲亚洲大胆

網(wǎng)站導(dǎo)航

首頁 > 解決方案 > 技術(shù)點滴

技術(shù)點滴

2018-07-06 sha-256 c代碼

最近做一個關(guān)于網(wǎng)頁認證的測試程序,要用到sha-256算法,因為本人比較懶,在國內(nèi)論壇著了半天沒有發(fā)現(xiàn)可以直接拿來用的。最后在github上下載了一個,直接能用,共享給大家參考:
sha256.h

點擊(此處)折疊或打開

  1. /*
  2. * SHA-256 implementation.
  3. *
  4. * Copyright (c) 2010 Ilya O. Levin, http://www.literatecode.com
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifdef _MSC_VER
  19. #ifndef uint8_t
  20. typedef unsigned __int8 uint8_t;
  21. #endif
  22. #ifndef uint32_t
  23. typedef unsigned __int32 uint32_t;
  24. #endif
  25. #ifndef uint64_t
  26. typedef __int64 int64_t;
  27. typedef unsigned __int64 uint64_t;
  28. #endif
  29. #else
  30. #include <stdint.h>
  31. #endif

  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif

  36.    typedef struct {
  37.        uint32_t buf[16];
  38.        uint32_t hash[8];
  39.        uint32_t len[2];
  40.    } sha256_context;

  41.    void sha256_init(sha256_context *);
  42.    void sha256_hash(sha256_context *, uint8_t * /* data */, uint32_t /* len */);
  43.    void sha256_done(sha256_context *, uint8_t * /* hash */);

  44. #ifdef __cplusplus
  45. }
  46. #endif
sha256.c

點擊(此處)折疊或打開

  1. /*
  2. * SHA-256 implementation.
  3. *
  4. * Copyright (c) 2010 Ilya O. Levin, http://www.literatecode.com
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #define SWAP_BYTES
  19. // #define USE_STD_MEMCPY
  20. #define SELF_TEST

  21. #ifdef USE_STD_MEMCPY
  22. #include <string.h>
  23. #endif
  24. #include "sha256.h"

  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif

  28. #define RL(x,n) (((x) << n) | ((x) >> (32 - n)))
  29. #define RR(x,n) (((x) >> n) | ((x) << (32 - n)))

  30. #define S0(x) (RR((x), 2) ^ RR((x),13) ^ RR((x),22))
  31. #define S1(x) (RR((x), 6) ^ RR((x),11) ^ RR((x),25))
  32. #define G0(x) (RR((x), 7) ^ RR((x),18) ^ ((x) >> 3))
  33. #define G1(x) (RR((x),17) ^ RR((x),19) ^ ((x) >> 10))

  34. #ifdef SWAP_BYTES
  35. #define BSWP(x,y) _bswapw((uint32_t *)(x), (uint32_t)(y))
  36. #else
  37. #define BSWP(p,n)
  38. #endif
  39. #ifdef USE_STD_MEMCPY
  40. #define MEMCP(x,y,z) memcpy((x),(y),(z))
  41. #else
  42. #define MEMCP(x,y,z) _memcp((x),(y),(z))
  43. #endif

  44. #ifndef __cdecl
  45. #define __cdecl
  46. #endif

  47. static const uint32_t K[64] = {
  48.      0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  49.      0x3956c25b, 0x59f111f1, 0x923

JTJDoZ35YcstVvF07jLv+sza2KIiTiW6Wt9qcelzuzutwXu5wjb9MSd7yxVJn+b/B1U31hoxqSz4FFU7ACoix/GbKrrVtQullTVcVquOG1bDhOyculjKd82ZUWG93n6Fz1bTEHxco78p8LLB51az3eo3LsRH87sTdQe179+B2H8JVtfQS+UnB/JZWBBAiMJ1tiV5rmck5g7NLJtzqGokT3hVHoR1FhDv