ltc sync
Karel Miko
7 years ago
15 | 15 |
Hash open files, Tom St Denis
|
16 | 16 |
*/
|
17 | 17 |
|
18 | |
/**
|
19 | |
Hash data from an open file handle.
|
|
18 |
/**
|
|
19 |
Hash data from an open file handle.
|
20 | 20 |
@param hash The index of the hash you want to use
|
21 | 21 |
@param in The FILE* handle of the file you want to hash
|
22 | 22 |
@param out [out] The destination of the digest
|
23 | 23 |
@param outlen [in/out] The max size and resulting size of the digest
|
24 | |
@result CRYPT_OK if successful
|
|
24 |
@result CRYPT_OK if successful
|
25 | 25 |
*/
|
26 | 26 |
int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen)
|
27 | 27 |
{
|
9 | 9 |
*/
|
10 | 10 |
#include "tomcrypt.h"
|
11 | 11 |
|
12 | |
/**
|
|
12 |
/**
|
13 | 13 |
@file f9_file.c
|
14 | 14 |
f9 support, process a file, Tom St Denis
|
15 | 15 |
*/
|
|
28 | 28 |
*/
|
29 | 29 |
int f9_file(int cipher,
|
30 | 30 |
const unsigned char *key, unsigned long keylen,
|
31 | |
const char *filename,
|
|
31 |
const char *filename,
|
32 | 32 |
unsigned char *out, unsigned long *outlen)
|
33 | 33 |
{
|
34 | 34 |
#ifdef LTC_NO_FILE
|
9 | 9 |
*/
|
10 | 10 |
#include "tomcrypt.h"
|
11 | 11 |
|
12 | |
/**
|
|
12 |
/**
|
13 | 13 |
@file pmac_file.c
|
14 | |
PMAC implementation, process a file, by Tom St Denis
|
|
14 |
PMAC implementation, process a file, by Tom St Denis
|
15 | 15 |
*/
|
16 | 16 |
|
17 | 17 |
#ifdef LTC_PMAC
|
18 | 18 |
|
19 | 19 |
/**
|
20 | |
PMAC a file
|
|
20 |
PMAC a file
|
21 | 21 |
@param cipher The index of the cipher desired
|
22 | 22 |
@param key The secret key
|
23 | 23 |
@param keylen The length of the secret key (octets)
|
|
26 | 26 |
@param outlen [in/out] Max size and resulting size of the authentication tag
|
27 | 27 |
@return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
|
28 | 28 |
*/
|
29 | |
int pmac_file(int cipher,
|
|
29 |
int pmac_file(int cipher,
|
30 | 30 |
const unsigned char *key, unsigned long keylen,
|
31 | |
const char *filename,
|
|
31 |
const char *filename,
|
32 | 32 |
unsigned char *out, unsigned long *outlen)
|
33 | 33 |
{
|
34 | 34 |
#ifdef LTC_NO_FILE
|
9 | 9 |
*/
|
10 | 10 |
#include "tomcrypt.h"
|
11 | 11 |
|
12 | |
/**
|
|
12 |
/**
|
13 | 13 |
@file xcbc_file.c
|
14 | 14 |
XCBC support, process a file, Tom St Denis
|
15 | 15 |
*/
|
|
26 | 26 |
@param outlen [in/out] The max size and resulting size of the authentication tag
|
27 | 27 |
@return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
|
28 | 28 |
*/
|
29 | |
int xcbc_file(int cipher,
|
|
29 |
int xcbc_file(int cipher,
|
30 | 30 |
const unsigned char *key, unsigned long keylen,
|
31 | |
const char *filename,
|
|
31 |
const char *filename,
|
32 | 32 |
unsigned char *out, unsigned long *outlen)
|
33 | 33 |
{
|
34 | 34 |
#ifdef LTC_NO_FILE
|
19 | 19 |
#if defined(LTC_BASE64) || defined (LTC_BASE64_URL)
|
20 | 20 |
|
21 | 21 |
#if defined(LTC_BASE64)
|
22 | |
static const char *codes_base64 =
|
|
22 |
static const char * const codes_base64 =
|
23 | 23 |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
24 | 24 |
#endif /* LTC_BASE64 */
|
25 | 25 |
|
26 | 26 |
#if defined(LTC_BASE64_URL)
|
27 | |
static const char *codes_base64url =
|
|
27 |
static const char * const codes_base64url =
|
28 | 28 |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
29 | 29 |
#endif /* LTC_BASE64_URL */
|
30 | 30 |
|
|
74 | 74 |
*p = '\0';
|
75 | 75 |
|
76 | 76 |
/* return ok */
|
77 | |
*outlen = p - out;
|
|
77 |
*outlen = (unsigned long)(p - out);
|
78 | 78 |
return CRYPT_OK;
|
79 | 79 |
}
|
80 | 80 |
|
|
109 | 109 |
{
|
110 | 110 |
return _base64_encode_internal(in, inlen, out, outlen, codes_base64url, 0);
|
111 | 111 |
}
|
|
112 |
|
|
113 |
int base64url_strict_encode(const unsigned char *in, unsigned long inlen,
|
|
114 |
unsigned char *out, unsigned long *outlen)
|
|
115 |
{
|
|
116 |
return _base64_encode_internal(in, inlen, out, outlen, codes_base64url, 1);
|
|
117 |
}
|
112 | 118 |
#endif /* LTC_BASE64_URL */
|
113 | 119 |
|
114 | 120 |
#endif
|
93 | 93 |
}
|
94 | 94 |
|
95 | 95 |
/* skip header */
|
96 | |
ptr = buf + 1;
|
|
96 |
ptr = buf + 1;
|
97 | 97 |
|
98 | |
/* now skip length data */
|
99 | |
x = *ptr++;
|
100 | |
if (x >= 0x80) {
|
101 | |
ptr += (x & 0x7F);
|
102 | |
}
|
|
98 |
/* now skip length data */
|
|
99 |
x = *ptr++;
|
|
100 |
if (x >= 0x80) {
|
|
101 |
ptr += (x & 0x7F);
|
|
102 |
}
|
103 | 103 |
|
104 | |
/* get the size of the static header */
|
105 | |
hdrlen = ptr - buf;
|
|
104 |
/* get the size of the static header */
|
|
105 |
hdrlen = ptr - buf;
|
106 | 106 |
|
107 | 107 |
|
108 | 108 |
/* scan for edges */
|
|
139 | 139 |
XMEMCPY(out, buf, hdrlen);
|
140 | 140 |
|
141 | 141 |
/* copy+sort using edges+indecies to output from buffer */
|
142 | |
for (y = hdrlen, x = 0; x < inlen; x++) {
|
|
142 |
for (y = (unsigned long)hdrlen, x = 0; x < inlen; x++) {
|
143 | 143 |
XMEMCPY(out+y, edges[x].start, edges[x].size);
|
144 | 144 |
y += edges[x].size;
|
145 | 145 |
}
|
110 | 110 |
}
|
111 | 111 |
|
112 | 112 |
/* grab the next msb from the ltiplicand */
|
113 | |
i = (buf >> (MP_DIGIT_BIT - 1)) & 1;
|
|
113 |
i = (int)((buf >> (MP_DIGIT_BIT - 1)) & 1);
|
114 | 114 |
buf <<= 1;
|
115 | 115 |
|
116 | 116 |
if (mode == 0 && i == 0) {
|