Codebase list libcryptx-perl / b43ce3e
ltc sync Karel Miko 7 years ago
8 changed file(s) with 34 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
1010 #include "tomcrypt.h"
1111
1212 #ifndef LTC_NO_FILE
13 /**
13 /**
1414 @file hash_file.c
1515 Hash a file, Tom St Denis
1616 */
3535 }
3636
3737 in = fopen(fname, "rb");
38 if (in == NULL) {
38 if (in == NULL) {
3939 return CRYPT_FILE_NOTFOUND;
4040 }
4141
1515 Hash open files, Tom St Denis
1616 */
1717
18 /**
19 Hash data from an open file handle.
18 /**
19 Hash data from an open file handle.
2020 @param hash The index of the hash you want to use
2121 @param in The FILE* handle of the file you want to hash
2222 @param out [out] The destination of the digest
2323 @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
2525 */
2626 int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen)
2727 {
99 */
1010 #include "tomcrypt.h"
1111
12 /**
12 /**
1313 @file f9_file.c
1414 f9 support, process a file, Tom St Denis
1515 */
2828 */
2929 int f9_file(int cipher,
3030 const unsigned char *key, unsigned long keylen,
31 const char *filename,
31 const char *filename,
3232 unsigned char *out, unsigned long *outlen)
3333 {
3434 #ifdef LTC_NO_FILE
99 */
1010 #include "tomcrypt.h"
1111
12 /**
12 /**
1313 @file pmac_file.c
14 PMAC implementation, process a file, by Tom St Denis
14 PMAC implementation, process a file, by Tom St Denis
1515 */
1616
1717 #ifdef LTC_PMAC
1818
1919 /**
20 PMAC a file
20 PMAC a file
2121 @param cipher The index of the cipher desired
2222 @param key The secret key
2323 @param keylen The length of the secret key (octets)
2626 @param outlen [in/out] Max size and resulting size of the authentication tag
2727 @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
2828 */
29 int pmac_file(int cipher,
29 int pmac_file(int cipher,
3030 const unsigned char *key, unsigned long keylen,
31 const char *filename,
31 const char *filename,
3232 unsigned char *out, unsigned long *outlen)
3333 {
3434 #ifdef LTC_NO_FILE
99 */
1010 #include "tomcrypt.h"
1111
12 /**
12 /**
1313 @file xcbc_file.c
1414 XCBC support, process a file, Tom St Denis
1515 */
2626 @param outlen [in/out] The max size and resulting size of the authentication tag
2727 @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
2828 */
29 int xcbc_file(int cipher,
29 int xcbc_file(int cipher,
3030 const unsigned char *key, unsigned long keylen,
31 const char *filename,
31 const char *filename,
3232 unsigned char *out, unsigned long *outlen)
3333 {
3434 #ifdef LTC_NO_FILE
1919 #if defined(LTC_BASE64) || defined (LTC_BASE64_URL)
2020
2121 #if defined(LTC_BASE64)
22 static const char *codes_base64 =
22 static const char * const codes_base64 =
2323 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2424 #endif /* LTC_BASE64 */
2525
2626 #if defined(LTC_BASE64_URL)
27 static const char *codes_base64url =
27 static const char * const codes_base64url =
2828 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
2929 #endif /* LTC_BASE64_URL */
3030
7474 *p = '\0';
7575
7676 /* return ok */
77 *outlen = p - out;
77 *outlen = (unsigned long)(p - out);
7878 return CRYPT_OK;
7979 }
8080
109109 {
110110 return _base64_encode_internal(in, inlen, out, outlen, codes_base64url, 0);
111111 }
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 }
112118 #endif /* LTC_BASE64_URL */
113119
114120 #endif
9393 }
9494
9595 /* skip header */
96 ptr = buf + 1;
96 ptr = buf + 1;
9797
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 }
103103
104 /* get the size of the static header */
105 hdrlen = ptr - buf;
104 /* get the size of the static header */
105 hdrlen = ptr - buf;
106106
107107
108108 /* scan for edges */
139139 XMEMCPY(out, buf, hdrlen);
140140
141141 /* 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++) {
143143 XMEMCPY(out+y, edges[x].start, edges[x].size);
144144 y += edges[x].size;
145145 }
110110 }
111111
112112 /* grab the next msb from the ltiplicand */
113 i = (buf >> (MP_DIGIT_BIT - 1)) & 1;
113 i = (int)((buf >> (MP_DIGIT_BIT - 1)) & 1);
114114 buf <<= 1;
115115
116116 if (mode == 0 && i == 0) {