diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2019-07-02 03:06:52 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2019-07-02 12:36:27 +0200 |
commit | 564d93ff10b19dd15df6ea049bd7c9a9c99680c6 (patch) | |
tree | ee6523844280ff5874e8d7aff7c95f498ae769e0 /thirdparty/misc/base64.c | |
parent | 0268a4869ded42079d3f4c255406711c726e3df4 (diff) | |
download | redot-engine-564d93ff10b19dd15df6ea049bd7c9a9c99680c6.tar.gz |
CryptoCore class to access to base crypto utils.
Godot core needs MD5/SHA256/AES/Base64 which used to be provided by
separate libraries.
Since we bundle mbedtls in most cases, and we can easily only include
the needed sources if we so desire, let's use it.
To simplify library changes in the future, and better isolate header
dependencies all functions have been wrapped around inside a class in
`core/math/crypto_base.h`.
If the mbedtls module is disabled, we only bundle the needed source
files independently of the `builtin_mbedtls` option.
If the module is enabled, the `builtin_mbedtls` option works as usual.
Also remove some unused headers from StreamPeerMbedTLS which were
causing build issues.
Diffstat (limited to 'thirdparty/misc/base64.c')
-rw-r--r-- | thirdparty/misc/base64.c | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/thirdparty/misc/base64.c b/thirdparty/misc/base64.c deleted file mode 100644 index 0929ae5db5..0000000000 --- a/thirdparty/misc/base64.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * File: base64.c - * Description: Simple BASE64 conversion methods - * Author: Ari Edelkind - * License: Public Domain - * Website: http://episec.com/people/edelkind/c.html - */ - -#include <string.h> - -char b64string[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -long base64_encode (to, from, len) - char *to, *from; - unsigned int len; -{ - char *fromp = from; - char *top = to; - unsigned char cbyte; - unsigned char obyte; - char end[3]; - - for (; len >= 3; len -= 3) { - cbyte = *fromp++; - *top++ = b64string[(int)(cbyte >> 2)]; - obyte = (cbyte << 4) & 0x30; /* 0011 0000 */ - - cbyte = *fromp++; - obyte |= (cbyte >> 4); /* 0000 1111 */ - *top++ = b64string[(int)obyte]; - obyte = (cbyte << 2) & 0x3C; /* 0011 1100 */ - - cbyte = *fromp++; - obyte |= (cbyte >> 6); /* 0000 0011 */ - *top++ = b64string[(int)obyte]; - *top++ = b64string[(int)(cbyte & 0x3F)];/* 0011 1111 */ - } - - if (len) { - end[0] = *fromp++; - if (--len) end[1] = *fromp++; else end[1] = 0; - end[2] = 0; - - cbyte = end[0]; - *top++ = b64string[(int)(cbyte >> 2)]; - obyte = (cbyte << 4) & 0x30; /* 0011 0000 */ - - cbyte = end[1]; - obyte |= (cbyte >> 4); - *top++ = b64string[(int)obyte]; - obyte = (cbyte << 2) & 0x3C; /* 0011 1100 */ - - if (len) *top++ = b64string[(int)obyte]; - else *top++ = '='; - *top++ = '='; - } - *top = 0; - return top - to; -} - -/* badchar(): check if c is decent; puts either the */ -/* location of c or null into p. */ -#define badchar(c,p) (!(p = memchr(b64string, c, 64))) - -long base64_decode (to, from, len) - char *to, *from; - unsigned int len; -{ - char *fromp = from; - char *top = to; - char *p; - unsigned char cbyte; - unsigned char obyte; - int padding = 0; - - for (; len >= 4; len -= 4) { - if ((cbyte = *fromp++) == '=') cbyte = 0; - else { - if (badchar(cbyte, p)) return -1; - cbyte = (p - b64string); - } - obyte = cbyte << 2; /* 1111 1100 */ - - if ((cbyte = *fromp++) == '=') cbyte = 0; - else { - if (badchar(cbyte, p)) return -1; - cbyte = p - b64string; - } - obyte |= cbyte >> 4; /* 0000 0011 */ - *top++ = obyte; - - obyte = cbyte << 4; /* 1111 0000 */ - if ((cbyte = *fromp++) == '=') { cbyte = 0; padding++; } - else { - padding = 0; - if (badchar (cbyte, p)) return -1; - cbyte = p - b64string; - } - obyte |= cbyte >> 2; /* 0000 1111 */ - *top++ = obyte; - - obyte = cbyte << 6; /* 1100 0000 */ - if ((cbyte = *fromp++) == '=') { cbyte = 0; padding++; } - else { - padding = 0; - if (badchar (cbyte, p)) return -1; - cbyte = p - b64string; - } - obyte |= cbyte; /* 0011 1111 */ - *top++ = obyte; - } - - *top = 0; - if (len) return -1; - return (top - to) - padding; -} - |