• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FDRM_CRYPTO_FX_CRYPT_H_
8 #define CORE_FDRM_CRYPTO_FX_CRYPT_H_
9 
10 #include "core/fxcrt/fx_system.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 typedef struct {
17   int32_t x;
18   int32_t y;
19   int32_t m[256];
20 } CRYPT_rc4_context;
21 
22 typedef struct {
23   uint32_t total[2];
24   uint32_t state[4];
25   uint8_t buffer[64];
26 } CRYPT_md5_context;
27 
28 typedef struct {
29   unsigned int h[5];
30   unsigned char block[64];
31   int blkused;
32   unsigned int lenhi;
33   unsigned int lenlo;
34 } CRYPT_sha1_context;
35 
36 typedef struct {
37   uint32_t total[2];
38   uint32_t state[8];
39   uint8_t buffer[64];
40 } CRYPT_sha256_context;
41 
42 typedef struct {
43   uint64_t total[2];
44   uint64_t state[8];
45   uint8_t buffer[128];
46 } CRYPT_sha384_context;
47 
48 void CRYPT_ArcFourCryptBlock(uint8_t* data,
49                              uint32_t size,
50                              const uint8_t* key,
51                              uint32_t keylen);
52 void CRYPT_ArcFourSetup(CRYPT_rc4_context* context,
53                         const uint8_t* key,
54                         uint32_t length);
55 void CRYPT_ArcFourCrypt(CRYPT_rc4_context* context,
56                         uint8_t* data,
57                         uint32_t size);
58 
59 void CRYPT_AESSetKey(void* context,
60                      uint32_t blocklen,
61                      const uint8_t* key,
62                      uint32_t keylen,
63                      bool bEncrypt);
64 void CRYPT_AESSetIV(void* context, const uint8_t* iv);
65 void CRYPT_AESDecrypt(void* context,
66                       uint8_t* dest,
67                       const uint8_t* src,
68                       uint32_t size);
69 void CRYPT_AESEncrypt(void* context,
70                       uint8_t* dest,
71                       const uint8_t* src,
72                       uint32_t size);
73 
74 void CRYPT_MD5Start(CRYPT_md5_context* context);
75 void CRYPT_MD5Update(CRYPT_md5_context* context,
76                      const uint8_t* data,
77                      uint32_t size);
78 void CRYPT_MD5Finish(CRYPT_md5_context* context, uint8_t digest[16]);
79 void CRYPT_MD5Generate(const uint8_t* data, uint32_t size, uint8_t digest[16]);
80 
81 void CRYPT_SHA1Start(CRYPT_sha1_context* context);
82 void CRYPT_SHA1Update(CRYPT_sha1_context* context,
83                       const uint8_t* data,
84                       uint32_t size);
85 void CRYPT_SHA1Finish(CRYPT_sha1_context* context, uint8_t digest[20]);
86 void CRYPT_SHA1Generate(const uint8_t* data, uint32_t size, uint8_t digest[20]);
87 
88 void CRYPT_SHA256Start(CRYPT_sha256_context* context);
89 void CRYPT_SHA256Update(CRYPT_sha256_context* context,
90                         const uint8_t* data,
91                         uint32_t size);
92 void CRYPT_SHA256Finish(CRYPT_sha256_context* context, uint8_t digest[32]);
93 void CRYPT_SHA256Generate(const uint8_t* data,
94                           uint32_t size,
95                           uint8_t digest[32]);
96 
97 void CRYPT_SHA384Start(CRYPT_sha384_context* context);
98 void CRYPT_SHA384Update(CRYPT_sha384_context* context,
99                         const uint8_t* data,
100                         uint32_t size);
101 void CRYPT_SHA384Finish(CRYPT_sha384_context* context, uint8_t digest[48]);
102 void CRYPT_SHA384Generate(const uint8_t* data,
103                           uint32_t size,
104                           uint8_t digest[48]);
105 
106 void CRYPT_SHA512Start(void* context);
107 void CRYPT_SHA512Update(void* context, const uint8_t* data, uint32_t size);
108 void CRYPT_SHA512Finish(void* context, uint8_t digest[64]);
109 void CRYPT_SHA512Generate(const uint8_t* data,
110                           uint32_t size,
111                           uint8_t digest[64]);
112 #ifdef __cplusplus
113 };
114 #endif
115 
116 #endif  // CORE_FDRM_CRYPTO_FX_CRYPT_H_
117