misc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. /*
  2. * Header for miscellaneous helper functions, mostly defined in the
  3. * utils subdirectory.
  4. */
  5. #ifndef PUTTY_MISC_H
  6. #define PUTTY_MISC_H
  7. #include "defs.h"
  8. #include "puttymem.h"
  9. #include "marshal.h"
  10. #include <stdio.h> /* for FILE * */
  11. #include <stdarg.h> /* for va_list */
  12. #include <stdlib.h> /* for abort */
  13. #include <time.h> /* for struct tm */
  14. #include <limits.h> /* for INT_MAX/MIN */
  15. #include <assert.h> /* for assert (obviously) */
  16. unsigned long parse_blocksize(const char *bs);
  17. char ctrlparse(char *s, char **next);
  18. size_t host_strcspn(const char *s, const char *set);
  19. char *host_strchr(const char *s, int c);
  20. char *host_strrchr(const char *s, int c);
  21. char *host_strduptrim(const char *s);
  22. char *dupstr(const char *s);
  23. char *dupcat_fn(const char *s1, ...);
  24. #define dupcat(...) dupcat_fn(__VA_ARGS__, (const char *)NULL)
  25. char *dupprintf(const char *fmt, ...) PRINTF_LIKE(1, 2);
  26. char *dupvprintf(const char *fmt, va_list ap);
  27. void burnstr(char *string);
  28. /*
  29. * The visible part of a strbuf structure. There's a surrounding
  30. * implementation struct in strbuf.c, which isn't exposed to client
  31. * code.
  32. */
  33. struct strbuf {
  34. char *s;
  35. unsigned char *u;
  36. size_t len;
  37. BinarySink_IMPLEMENTATION;
  38. };
  39. /* strbuf constructors: strbuf_new_nm and strbuf_new differ in that a
  40. * strbuf constructed using the _nm version will resize itself by
  41. * alloc/copy/smemclr/free instead of realloc. Use that version for
  42. * data sensitive enough that it's worth costing performance to
  43. * avoid copies of it lingering in process memory. */
  44. strbuf *strbuf_new(void);
  45. strbuf *strbuf_new_nm(void);
  46. /* Helpers to allocate a strbuf containing an existing string */
  47. strbuf *strbuf_dup(ptrlen string);
  48. strbuf *strbuf_dup_nm(ptrlen string);
  49. void strbuf_free(strbuf *buf);
  50. void *strbuf_append(strbuf *buf, size_t len);
  51. void strbuf_shrink_to(strbuf *buf, size_t new_len);
  52. void strbuf_shrink_by(strbuf *buf, size_t amount_to_remove);
  53. char *strbuf_to_str(strbuf *buf); /* does free buf, but you must free result */
  54. static inline void strbuf_clear(strbuf *buf) { strbuf_shrink_to(buf, 0); }
  55. bool strbuf_chomp(strbuf *buf, char char_to_remove);
  56. strbuf *strbuf_new_for_agent_query(void);
  57. void strbuf_finalise_agent_query(strbuf *buf);
  58. /* String-to-Unicode converters that auto-allocate the destination and
  59. * work around the rather deficient interface of mb_to_wc. */
  60. wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string, int len);
  61. wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string);
  62. char *dup_wc_to_mb_c(int codepage, int flags, const wchar_t *string, int len,
  63. const char *defchr);
  64. char *dup_wc_to_mb(int codepage, int flags, const wchar_t *string,
  65. const char *defchr);
  66. static inline int toint(unsigned u)
  67. {
  68. /*
  69. * Convert an unsigned to an int, without running into the
  70. * undefined behaviour which happens by the strict C standard if
  71. * the value overflows. You'd hope that sensible compilers would
  72. * do the sensible thing in response to a cast, but actually I
  73. * don't trust modern compilers not to do silly things like
  74. * assuming that _obviously_ you wouldn't have caused an overflow
  75. * and so they can elide an 'if (i < 0)' test immediately after
  76. * the cast.
  77. *
  78. * Sensible compilers ought of course to optimise this entire
  79. * function into 'just return the input value', and since it's
  80. * also declared inline, elide it completely in their output.
  81. */
  82. if (u <= (unsigned)INT_MAX)
  83. return (int)u;
  84. else if (u >= (unsigned)INT_MIN) /* wrap in cast _to_ unsigned is OK */
  85. return INT_MIN + (int)(u - (unsigned)INT_MIN);
  86. else
  87. return INT_MIN; /* fallback; should never occur on binary machines */
  88. }
  89. char *fgetline(FILE *fp);
  90. bool read_file_into(BinarySink *bs, FILE *fp);
  91. char *chomp(char *str);
  92. bool strstartswith(const char *s, const char *t);
  93. bool strendswith(const char *s, const char *t);
  94. void base64_encode_atom(const unsigned char *data, int n, char *out);
  95. int base64_decode_atom(const char *atom, unsigned char *out);
  96. void base64_decode_bs(BinarySink *bs, ptrlen data);
  97. void base64_decode_fp(FILE *fp, ptrlen data);
  98. strbuf *base64_decode_sb(ptrlen data);
  99. void base64_encode_bs(BinarySink *bs, ptrlen data, int cpl);
  100. void base64_encode_fp(FILE *fp, ptrlen data, int cpl);
  101. strbuf *base64_encode_sb(ptrlen data, int cpl);
  102. bool base64_valid(ptrlen data);
  103. void percent_encode_bs(BinarySink *bs, ptrlen data, const char *badchars);
  104. void percent_encode_fp(FILE *fp, ptrlen data, const char *badchars);
  105. strbuf *percent_encode_sb(ptrlen data, const char *badchars);
  106. void percent_decode_bs(BinarySink *bs, ptrlen data);
  107. void percent_decode_fp(FILE *fp, ptrlen data);
  108. strbuf *percent_decode_sb(ptrlen data);
  109. struct bufchain_granule;
  110. struct bufchain_tag {
  111. struct bufchain_granule *head, *tail;
  112. size_t buffersize; /* current amount of buffered data */
  113. void (*queue_idempotent_callback)(IdempotentCallback *ic);
  114. IdempotentCallback *ic;
  115. };
  116. void bufchain_init(bufchain *ch);
  117. void bufchain_clear(bufchain *ch);
  118. size_t bufchain_size(bufchain *ch);
  119. void bufchain_add(bufchain *ch, const void *data, size_t len);
  120. ptrlen bufchain_prefix(bufchain *ch);
  121. void bufchain_consume(bufchain *ch, size_t len);
  122. void bufchain_fetch(bufchain *ch, void *data, size_t len);
  123. void bufchain_fetch_consume(bufchain *ch, void *data, size_t len);
  124. bool bufchain_try_consume(bufchain *ch, size_t len);
  125. bool bufchain_try_fetch(bufchain *ch, void *data, size_t len);
  126. bool bufchain_try_fetch_consume(bufchain *ch, void *data, size_t len);
  127. size_t bufchain_fetch_consume_up_to(bufchain *ch, void *data, size_t len);
  128. void bufchain_set_callback_inner(
  129. bufchain *ch, IdempotentCallback *ic,
  130. void (*queue_idempotent_callback)(IdempotentCallback *ic));
  131. static inline void bufchain_set_callback(bufchain *ch, IdempotentCallback *ic)
  132. {
  133. extern void queue_idempotent_callback(struct IdempotentCallback *ic);
  134. /* Wrapper that puts in the standard queue_idempotent_callback
  135. * function. Lives here rather than in bufchain.c so that
  136. * standalone programs can use the bufchain facility without this
  137. * optional callback feature and not need to provide a stub of
  138. * queue_idempotent_callback. */
  139. bufchain_set_callback_inner(ch, ic, queue_idempotent_callback);
  140. }
  141. bool validate_manual_hostkey(char *key);
  142. struct tm ltime(void);
  143. /*
  144. * Special form of strcmp which can cope with NULL inputs. NULL is
  145. * defined to sort before even the empty string.
  146. */
  147. int nullstrcmp(const char *a, const char *b);
  148. static inline ptrlen make_ptrlen(const void *ptr, size_t len)
  149. {
  150. ptrlen pl;
  151. pl.ptr = ptr;
  152. pl.len = len;
  153. return pl;
  154. }
  155. static inline const void *ptrlen_end(ptrlen pl)
  156. {
  157. return (const char *)pl.ptr + pl.len;
  158. }
  159. static inline ptrlen make_ptrlen_startend(const void *startv, const void *endv)
  160. {
  161. const char *start = (const char *)startv, *end = (const char *)endv;
  162. assert(end >= start);
  163. ptrlen pl;
  164. pl.ptr = start;
  165. pl.len = end - start;
  166. return pl;
  167. }
  168. static inline ptrlen ptrlen_from_asciz(const char *str)
  169. {
  170. return make_ptrlen(str, strlen(str));
  171. }
  172. static inline ptrlen ptrlen_from_strbuf(strbuf *sb)
  173. {
  174. return make_ptrlen(sb->u, sb->len);
  175. }
  176. bool ptrlen_eq_string(ptrlen pl, const char *str);
  177. bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2);
  178. int ptrlen_strcmp(ptrlen pl1, ptrlen pl2);
  179. /* ptrlen_startswith and ptrlen_endswith write through their 'tail'
  180. * argument if and only if it is non-NULL and they return true. Hence
  181. * you can write ptrlen_startswith(thing, prefix, &thing), writing
  182. * back to the same ptrlen it read from, to remove a prefix if present
  183. * and say whether it did so. */
  184. bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail);
  185. bool ptrlen_endswith(ptrlen whole, ptrlen suffix, ptrlen *tail);
  186. ptrlen ptrlen_get_word(ptrlen *input, const char *separators);
  187. bool ptrlen_contains(ptrlen input, const char *characters);
  188. bool ptrlen_contains_only(ptrlen input, const char *characters);
  189. char *mkstr(ptrlen pl);
  190. int string_length_for_printf(size_t);
  191. /* Derive two printf arguments from a ptrlen, suitable for "%.*s" */
  192. #define PTRLEN_PRINTF(pl) \
  193. string_length_for_printf((pl).len), (const char *)(pl).ptr
  194. /* Make a ptrlen out of a compile-time string literal. We try to
  195. * enforce that it _is_ a string literal by token-pasting "" on to it,
  196. * which should provoke a compile error if it's any other kind of
  197. * string. */
  198. #define PTRLEN_LITERAL(stringlit) \
  199. TYPECHECK("" stringlit "", make_ptrlen(stringlit, sizeof(stringlit)-1))
  200. /* Make a ptrlen out of a compile-time string literal in a way that
  201. * allows you to declare the ptrlen itself as a compile-time initialiser. */
  202. #define PTRLEN_DECL_LITERAL(stringlit) \
  203. { TYPECHECK("" stringlit "", stringlit), sizeof(stringlit)-1 }
  204. /* Make a ptrlen out of a constant byte array. */
  205. #define PTRLEN_FROM_CONST_BYTES(a) make_ptrlen(a, sizeof(a))
  206. void wordwrap(BinarySink *bs, ptrlen input, size_t maxwid);
  207. /* Wipe sensitive data out of memory that's about to be freed. Simpler
  208. * than memset because we don't need the fill char parameter; also
  209. * attempts (by fiddly use of volatile) to inhibit the compiler from
  210. * over-cleverly trying to optimise the memset away because it knows
  211. * the variable is going out of scope. */
  212. void smemclr(void *b, size_t len);
  213. /* Compare two fixed-length chunks of memory for equality, without
  214. * data-dependent control flow (so an attacker with a very accurate
  215. * stopwatch can't try to guess where the first mismatching byte was).
  216. * Returns 0 for mismatch or 1 for equality (unlike memcmp), hinted at
  217. * by the 'eq' in the name. */
  218. unsigned smemeq(const void *av, const void *bv, size_t len);
  219. /* Encode a single UTF-8 character. Assumes that illegal characters
  220. * (such as things in the surrogate range, or > 0x10FFFF) have already
  221. * been removed. */
  222. size_t encode_utf8(void *output, unsigned long ch);
  223. /* Encode a wide-character string into UTF-8. Tolerates surrogates if
  224. * sizeof(wchar_t) == 2, assuming that in that case the wide string is
  225. * encoded in UTF-16. */
  226. char *encode_wide_string_as_utf8(const wchar_t *wstr);
  227. /* Decode a single UTF-8 character. Returns U+FFFD for any of the
  228. * illegal cases. */
  229. unsigned long decode_utf8(const char **utf8);
  230. /* Decode a single UTF-8 character to an output buffer of the
  231. * platform's wchar_t. May write a pair of surrogates if
  232. * sizeof(wchar_t) == 2, assuming that in that case the wide string is
  233. * encoded in UTF-16. Otherwise, writes one character. Returns the
  234. * number written. */
  235. size_t decode_utf8_to_wchar(const char **utf8, wchar_t *out);
  236. /* Write a string out in C string-literal format. */
  237. void write_c_string_literal(FILE *fp, ptrlen str);
  238. char *buildinfo(const char *newline);
  239. /*
  240. * A function you can put at points in the code where execution should
  241. * never reach in the first place. Better than assert(false), or even
  242. * assert(false && "some explanatory message"), because some compilers
  243. * don't interpret assert(false) as a declaration of unreachability,
  244. * so they may still warn about pointless things like some variable
  245. * not being initialised on the unreachable code path.
  246. *
  247. * I follow the assertion with a call to abort() just in case someone
  248. * compiles with -DNDEBUG, and I wrap that abort inside my own
  249. * function labelled NORETURN just in case some unusual kind of system
  250. * header wasn't foresighted enough to label abort() itself that way.
  251. */
  252. static inline NORETURN void unreachable_internal(void) { abort(); }
  253. #define unreachable(msg) (assert(false && msg), unreachable_internal())
  254. /*
  255. * Debugging functions.
  256. *
  257. * Output goes to debug.log
  258. *
  259. * debug() is like printf().
  260. *
  261. * dmemdump() and dmemdumpl() both do memory dumps. The difference
  262. * is that dmemdumpl() is more suited for when the memory address is
  263. * important (say because you'll be recording pointer values later
  264. * on). dmemdump() is more concise.
  265. */
  266. #ifdef DEBUG
  267. void debug_printf(const char *fmt, ...) PRINTF_LIKE(1, 2);
  268. void debug_memdump(const void *buf, int len, bool L);
  269. #define debug(...) (debug_printf(__VA_ARGS__))
  270. #define dmemdump(buf,len) (debug_memdump(buf, len, false))
  271. #define dmemdumpl(buf,len) (debug_memdump(buf, len, true))
  272. #else
  273. #define debug(...) ((void)0)
  274. #define dmemdump(buf,len) ((void)0)
  275. #define dmemdumpl(buf,len) ((void)0)
  276. #endif
  277. #ifndef lenof
  278. #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
  279. #endif
  280. #ifndef min
  281. #define min(x,y) ( (x) < (y) ? (x) : (y) )
  282. #endif
  283. #ifndef max
  284. #define max(x,y) ( (x) > (y) ? (x) : (y) )
  285. #endif
  286. static inline uint64_t GET_64BIT_LSB_FIRST(const void *vp)
  287. {
  288. const uint8_t *p = (const uint8_t *)vp;
  289. return (((uint64_t)p[0] ) | ((uint64_t)p[1] << 8) |
  290. ((uint64_t)p[2] << 16) | ((uint64_t)p[3] << 24) |
  291. ((uint64_t)p[4] << 32) | ((uint64_t)p[5] << 40) |
  292. ((uint64_t)p[6] << 48) | ((uint64_t)p[7] << 56));
  293. }
  294. static inline void PUT_64BIT_LSB_FIRST(void *vp, uint64_t value)
  295. {
  296. uint8_t *p = (uint8_t *)vp;
  297. p[0] = (uint8_t)(value);
  298. p[1] = (uint8_t)(value >> 8);
  299. p[2] = (uint8_t)(value >> 16);
  300. p[3] = (uint8_t)(value >> 24);
  301. p[4] = (uint8_t)(value >> 32);
  302. p[5] = (uint8_t)(value >> 40);
  303. p[6] = (uint8_t)(value >> 48);
  304. p[7] = (uint8_t)(value >> 56);
  305. }
  306. static inline uint32_t GET_32BIT_LSB_FIRST(const void *vp)
  307. {
  308. const uint8_t *p = (const uint8_t *)vp;
  309. return (((uint32_t)p[0] ) | ((uint32_t)p[1] << 8) |
  310. ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24));
  311. }
  312. static inline void PUT_32BIT_LSB_FIRST(void *vp, uint32_t value)
  313. {
  314. uint8_t *p = (uint8_t *)vp;
  315. p[0] = (uint8_t)(value);
  316. p[1] = (uint8_t)(value >> 8);
  317. p[2] = (uint8_t)(value >> 16);
  318. p[3] = (uint8_t)(value >> 24);
  319. }
  320. static inline uint16_t GET_16BIT_LSB_FIRST(const void *vp)
  321. {
  322. const uint8_t *p = (const uint8_t *)vp;
  323. return (((uint16_t)p[0] ) | ((uint16_t)p[1] << 8));
  324. }
  325. static inline void PUT_16BIT_LSB_FIRST(void *vp, uint16_t value)
  326. {
  327. uint8_t *p = (uint8_t *)vp;
  328. p[0] = (uint8_t)(value);
  329. p[1] = (uint8_t)(value >> 8);
  330. }
  331. static inline uint64_t GET_64BIT_MSB_FIRST(const void *vp)
  332. {
  333. const uint8_t *p = (const uint8_t *)vp;
  334. return (((uint64_t)p[7] ) | ((uint64_t)p[6] << 8) |
  335. ((uint64_t)p[5] << 16) | ((uint64_t)p[4] << 24) |
  336. ((uint64_t)p[3] << 32) | ((uint64_t)p[2] << 40) |
  337. ((uint64_t)p[1] << 48) | ((uint64_t)p[0] << 56));
  338. }
  339. static inline void PUT_64BIT_MSB_FIRST(void *vp, uint64_t value)
  340. {
  341. uint8_t *p = (uint8_t *)vp;
  342. p[7] = (uint8_t)(value);
  343. p[6] = (uint8_t)(value >> 8);
  344. p[5] = (uint8_t)(value >> 16);
  345. p[4] = (uint8_t)(value >> 24);
  346. p[3] = (uint8_t)(value >> 32);
  347. p[2] = (uint8_t)(value >> 40);
  348. p[1] = (uint8_t)(value >> 48);
  349. p[0] = (uint8_t)(value >> 56);
  350. }
  351. static inline uint32_t GET_32BIT_MSB_FIRST(const void *vp)
  352. {
  353. const uint8_t *p = (const uint8_t *)vp;
  354. return (((uint32_t)p[3] ) | ((uint32_t)p[2] << 8) |
  355. ((uint32_t)p[1] << 16) | ((uint32_t)p[0] << 24));
  356. }
  357. static inline void PUT_32BIT_MSB_FIRST(void *vp, uint32_t value)
  358. {
  359. uint8_t *p = (uint8_t *)vp;
  360. p[3] = (uint8_t)(value);
  361. p[2] = (uint8_t)(value >> 8);
  362. p[1] = (uint8_t)(value >> 16);
  363. p[0] = (uint8_t)(value >> 24);
  364. }
  365. static inline uint16_t GET_16BIT_MSB_FIRST(const void *vp)
  366. {
  367. const uint8_t *p = (const uint8_t *)vp;
  368. return (((uint16_t)p[1] ) | ((uint16_t)p[0] << 8));
  369. }
  370. static inline void PUT_16BIT_MSB_FIRST(void *vp, uint16_t value)
  371. {
  372. uint8_t *p = (uint8_t *)vp;
  373. p[1] = (uint8_t)(value);
  374. p[0] = (uint8_t)(value >> 8);
  375. }
  376. /* For use in X11-related applications, an endianness-variable form of
  377. * {GET,PUT}_16BIT which expects 'endian' to be either 'B' or 'l' */
  378. static inline uint16_t GET_16BIT_X11(char endian, const void *p)
  379. {
  380. return endian == 'B' ? GET_16BIT_MSB_FIRST(p) : GET_16BIT_LSB_FIRST(p);
  381. }
  382. static inline void PUT_16BIT_X11(char endian, void *p, uint16_t value)
  383. {
  384. if (endian == 'B')
  385. PUT_16BIT_MSB_FIRST(p, value);
  386. else
  387. PUT_16BIT_LSB_FIRST(p, value);
  388. }
  389. /* Replace NULL with the empty string, permitting an idiom in which we
  390. * get a string (pointer,length) pair that might be NULL,0 and can
  391. * then safely say things like printf("%.*s", length, NULLTOEMPTY(ptr)) */
  392. static inline const char *NULLTOEMPTY(const char *s)
  393. {
  394. return s ? s : "";
  395. }
  396. /* StripCtrlChars, defined in stripctrl.c: an adapter you can put on
  397. * the front of one BinarySink and which functions as one in turn.
  398. * Interprets its input as a stream of multibyte characters in the
  399. * system locale, and removes any that are not either printable
  400. * characters or newlines. */
  401. struct StripCtrlChars {
  402. BinarySink_IMPLEMENTATION;
  403. /* and this is contained in a larger structure */
  404. };
  405. StripCtrlChars *stripctrl_new(
  406. BinarySink *bs_out, bool permit_cr, wchar_t substitution);
  407. StripCtrlChars *stripctrl_new_term_fn(
  408. BinarySink *bs_out, bool permit_cr, wchar_t substitution,
  409. Terminal *term, unsigned long (*translate)(
  410. Terminal *, term_utf8_decode *, unsigned char));
  411. #define stripctrl_new_term(bs, cr, sub, term) \
  412. stripctrl_new_term_fn(bs, cr, sub, term, term_translate)
  413. void stripctrl_retarget(StripCtrlChars *sccpub, BinarySink *new_bs_out);
  414. void stripctrl_reset(StripCtrlChars *sccpub);
  415. void stripctrl_free(StripCtrlChars *sanpub);
  416. void stripctrl_enable_line_limiting(StripCtrlChars *sccpub);
  417. char *stripctrl_string_ptrlen(StripCtrlChars *sccpub, ptrlen str);
  418. static inline char *stripctrl_string(StripCtrlChars *sccpub, const char *str)
  419. {
  420. return stripctrl_string_ptrlen(sccpub, ptrlen_from_asciz(str));
  421. }
  422. /*
  423. * A mechanism for loading a file from disk into a memory buffer where
  424. * it can be picked apart as a BinarySource.
  425. */
  426. struct LoadedFile {
  427. char *data;
  428. size_t len, max_size;
  429. BinarySource_IMPLEMENTATION;
  430. };
  431. typedef enum {
  432. LF_OK, /* file loaded successfully */
  433. LF_TOO_BIG, /* file didn't fit in buffer */
  434. LF_ERROR, /* error from stdio layer */
  435. } LoadFileStatus;
  436. LoadedFile *lf_new(size_t max_size);
  437. void lf_free(LoadedFile *lf);
  438. LoadFileStatus lf_load_fp(LoadedFile *lf, FILE *fp);
  439. LoadFileStatus lf_load(LoadedFile *lf, const Filename *filename);
  440. static inline ptrlen ptrlen_from_lf(LoadedFile *lf)
  441. { return make_ptrlen(lf->data, lf->len); }
  442. /* Set the memory block of 'size' bytes at 'out' to the bitwise XOR of
  443. * the two blocks of the same size at 'in1' and 'in2'.
  444. *
  445. * 'out' may point to exactly the same address as one of the inputs,
  446. * but if the input and output blocks overlap in any other way, the
  447. * result of this function is not guaranteed. No memmove-style effort
  448. * is made to handle difficult overlap cases. */
  449. void memxor(uint8_t *out, const uint8_t *in1, const uint8_t *in2, size_t size);
  450. /* Boolean expressions used in OpenSSH certificate configuration */
  451. bool cert_expr_valid(const char *expression,
  452. char **error_msg, ptrlen *error_loc);
  453. bool cert_expr_match_str(const char *expression,
  454. const char *hostname, unsigned port);
  455. /* Build a certificate expression out of hostname wildcards. Required
  456. * to handle legacy configuration from early in development, when
  457. * multiple wildcards were stored separately in config, implicitly
  458. * ORed together. */
  459. CertExprBuilder *cert_expr_builder_new(void);
  460. void cert_expr_builder_free(CertExprBuilder *eb);
  461. void cert_expr_builder_add(CertExprBuilder *eb, const char *wildcard);
  462. char *cert_expr_expression(CertExprBuilder *eb);
  463. #endif