// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 #pragma once #include #include "ctype.h" #include "puttymem.h" #include "assert.h" struct Filename { char *path; }; typedef struct Filename Filename; #define f_open(filename, mode, isprivate) ( fopen((filename)->path, (mode)) ) //32 char *dupstr(const char *s); //51 int toint(unsigned); char *fgetline(FILE *fp); int strstartswith(const char *s, const char *t); int strendswith(const char *s, const char *t); void base64_encode_atom(unsigned char *data, int n, char *out); int base64_decode_atom(char *atom, unsigned char *out); //78 /* Wipe sensitive data out of memory that's about to be freed. Simpler * than memset because we don't need the fill char parameter; also * attempts (by fiddly use of volatile) to inhibit the compiler from * over-cleverly trying to optimise the memset away because it knows * the variable is going out of scope. */ void smemclr(void *b, size_t len); /* Compare two fixed-length chunks of memory for equality, without * data-dependent control flow (so an attacker with a very accurate * stopwatch can't try to guess where the first mismatching byte was). * Returns 0 for mismatch or 1 for equality (unlike memcmp), hinted at * by the 'eq' in the name. */ int smemeq(const void *av, const void *bv, size_t len); //117 #ifndef lenof #define lenof(x) ( (sizeof((x))) / (sizeof(*(x)))) #endif //128 #define GET_32BIT_LSB_FIRST(cp) \ (((unsigned long)(unsigned char)(cp)[0]) | \ ((unsigned long)(unsigned char)(cp)[1] << 8) | \ ((unsigned long)(unsigned char)(cp)[2] << 16) | \ ((unsigned long)(unsigned char)(cp)[3] << 24)) #define PUT_32BIT_LSB_FIRST(cp, value) ( \ (cp)[0] = (unsigned char)(value), \ (cp)[1] = (unsigned char)((value) >> 8), \ (cp)[2] = (unsigned char)((value) >> 16), \ (cp)[3] = (unsigned char)((value) >> 24) ) #define GET_16BIT_LSB_FIRST(cp) \ (((unsigned long)(unsigned char)(cp)[0]) | \ ((unsigned long)(unsigned char)(cp)[1] << 8)) #define PUT_16BIT_LSB_FIRST(cp, value) ( \ (cp)[0] = (unsigned char)(value), \ (cp)[1] = (unsigned char)((value) >> 8) ) #define GET_32BIT_MSB_FIRST(cp) \ (((unsigned long)(unsigned char)(cp)[0] << 24) | \ ((unsigned long)(unsigned char)(cp)[1] << 16) | \ ((unsigned long)(unsigned char)(cp)[2] << 8) | \ ((unsigned long)(unsigned char)(cp)[3])) #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp) #define PUT_32BIT_MSB_FIRST(cp, value) ( \ (cp)[0] = (unsigned char)((value) >> 24), \ (cp)[1] = (unsigned char)((value) >> 16), \ (cp)[2] = (unsigned char)((value) >> 8), \ (cp)[3] = (unsigned char)(value) ) #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value) #define GET_16BIT_MSB_FIRST(cp) \ (((unsigned long)(unsigned char)(cp)[0] << 8) | \ ((unsigned long)(unsigned char)(cp)[1])) #define PUT_16BIT_MSB_FIRST(cp, value) ( \ (cp)[0] = (unsigned char)((value) >> 8), \ (cp)[1] = (unsigned char)(value) )