This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
IMPORTANT!!! DO NOT USE THIS. It works, but you'll probably get it wrong, | |
because it must be keyed with at least 128 bits of entropy, and where | |
do you get this entropy, huh? | |
- In a browser, you get it from window.crypto.getRandomValues(). | |
- In Node, you get it from crypto.randomBytes() | |
Now LOOK AT YOU! You already have secure ways to generate random bytes, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generate a random UUIDv4. | |
* @return string UUID | |
*/ | |
function generate_uuid() | |
{ | |
$b = random_bytes(16); | |
$b[6] = chr(ord($b[6]) & 0x0f | 0x40); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: this is for scrypt implementation, which doesn't use diagonal constants, | |
// so the order of loading from x is different than in normal Salsa20 implementation. | |
function salsa20_8(x) { | |
var j0 = (x[ 0] & 0xff) | ((x[ 1] & 0xff)<<8) | ((x[ 2] & 0xff)<<16) | ((x[ 3] & 0xff)<<24); | |
var j1 = (x[ 4] & 0xff) | ((x[ 5] & 0xff)<<8) | ((x[ 6] & 0xff)<<16) | ((x[ 7] & 0xff)<<24); | |
var j2 = (x[ 8] & 0xff) | ((x[ 9] & 0xff)<<8) | ((x[10] & 0xff)<<16) | ((x[11] & 0xff)<<24); | |
var j3 = (x[12] & 0xff) | ((x[13] & 0xff)<<8) | ((x[14] & 0xff)<<16) | ((x[15] & 0xff)<<24); | |
var j4 = (x[16] & 0xff) | ((x[17] & 0xff)<<8) | ((x[18] & 0xff)<<16) | ((x[19] & 0xff)<<24); | |
var j5 = (x[20] & 0xff) | ((x[21] & 0xff)<<8) | ((x[22] & 0xff)<<16) | ((x[23] & 0xff)<<24); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cryptopass by dchest | |
# Based on: | |
# pbkdf2.py -- library to calculate keys from passwords | |
# Copyright (C) 2010 Tobias Ammann | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License as | |
# published by the Free Software Foundation; either version 3 of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// randomString(length) | |
// -------------------- | |
// | |
// Generates and returns a cryptographically secure | |
// uniform alphanumeric random string. | |
// | |
// Examples: | |
// | |
// randomString(14) // "oXYWpc1vODNR3M" | |
// randomString.hex(8) // "663c722b65943b9b" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// String ranges: strange('A-Za-z0-9+/') -> "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy012345678+/" | |
const strange = s => s.replace(/(.)-(.)/g, (_, x, y) => { for (var i = x.charCodeAt(0) + 1; i < y.charCodeAt(0); i++) x += String.fromCharCode(i); return x }) | |
// Base64 encoding of Uint8Array of ArrayBuffer and decoding to Uint8Array | |
const encodeBase64 = a => btoa(Array.from(a instanceof ArrayBuffer ? new Uint8Array(a) : a).map(x => String.fromCharCode(x)).join('')); | |
const encodeBase64url = a => encodeBase64(a).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); // no padding | |
const decodeBase64 = s => Uint8Array.from(atob(s), x => x.charCodeAt(0)); | |
// TODO: decodeBase64url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Gimli permutation - https://gimli.cr.yp.to */ | |
function gimli(s) { | |
var r, x, y, z, | |
a = s[ 0] | s[ 1] << 8 | s[ 2] << 16 | s[ 3] << 24, | |
b = s[ 4] | s[ 5] << 8 | s[ 6] << 16 | s[ 7] << 24, | |
c = s[ 8] | s[ 9] << 8 | s[10] << 16 | s[11] << 24, | |
d = s[12] | s[13] << 8 | s[14] << 16 | s[15] << 24, | |
e = s[16] | s[17] << 8 | s[18] << 16 | s[19] << 24, | |
f = s[20] | s[21] << 8 | s[22] << 16 | s[23] << 24, | |
g = s[24] | s[25] << 8 | s[26] << 16 | s[27] << 24, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
dchest's PureCSS Tweaks | |
https://gist.github.com/dchest/500746c2e41baaafcab3 | |
*/ | |
* { | |
-webkit-box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
box-sizing: border-box; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
fossil extra | tr '\n' '\0' | xargs -0 -t fossil add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Written by Dmitry Chestnykh. Public domain. */ | |
#include <err.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <time.h> | |
#include <openssl/blowfish.h> | |
#include <openssl/lhash.h> | |
/* Encryption and decryption */ |