Skip to content

Instantly share code, notes, and snippets.

View devi's full-sized avatar
⛰️
Off-Grid

Devi Mandiri devi

⛰️
Off-Grid
View GitHub Profile
@devi
devi / crypto_hash_sha256.js
Last active August 29, 2015 14:02
sha256
/* crypto_hash - sha256 */
// Written in 2014 by Devi Mandiri. Public domain.
//
// Implementation derived from TweetNaCl version 20140427.
// See for details: http://tweetnacl.cr.yp.to/
//
function load(x, pos) {
return x[pos+3] | (x[pos+2]<<8) | (x[pos+1]<<16) | (x[pos]<<24);
}
@devi
devi / KummerScalarmult.js
Created June 2, 2014 13:59
Kummer scalar multiplication for Javascript
/**
* kummer scalar multiplication - ref5
*
* ported from SUPERCOP 20140529
*
* see for details: http://bench.cr.yp.to/supercop.html
*/
var KummerScalarmult = (function() {
/* bitwise dance helper*/
@devi
devi / blake2s.min.js
Last active August 29, 2015 14:01
(uglified) blake2s implementation for javascript
!function(n){"use strict";function e(n,e){var r=255&n[e];return r|=(255&n[e+1])<<8,r|=(255&n[e+2])<<16,r|=(255&n[e+3])<<24}function r(n,e,r){n[e]=255&r,r>>>=8,n[e+1]=255&r,r>>>=8,n[e+2]=255&r,r>>>=8,n[e+3]=255&r}function f(){for(var n=0,e=0;e<arguments.length;e++)n=n+arguments[e]>>>0;return n}function t(n,e){return(n>>>e|n<<32-e)>>>0}function o(n,e,r,o,u,i){g[r]=f(g[r],g[o],p[d[n][2*e]]),g[i]=t(g[i]^g[r],16),g[u]=f(g[u],g[i]),g[o]=t(g[o]^g[u],12),g[r]=f(g[r],g[o],p[d[n][2*e+1]]),g[i]=t(g[i]^g[r],8),g[u]=f(g[u],g[i]),g[o]=t(g[o]^g[u],7)}function u(n,r){n.t[0]+=r,n.t[1]+=n.t[0]<r?1:0;var f=0;for(f=16;f--;)p[f]=e(n.buf,4*f);for(f=8;f--;)g[f]=n.h[f];for(g[8]=b[0],g[9]=b[1],g[10]=b[2],g[11]=b[3],g[12]=(b[4]^n.t[0])>>>0,g[13]=(b[5]^n.t[1])>>>0,g[14]=(b[6]^n.f[0])>>>0,g[15]=(b[7]^n.f[1])>>>0,f=0;10>f;f++)o(f,0,0,4,8,12),o(f,1,1,5,9,13),o(f,2,2,6,10,14),o(f,3,3,7,11,15),o(f,4,0,5,10,15),o(f,5,1,6,11,12),o(f,6,2,7,8,13),o(f,7,3,4,9,14);for(f=8;f--;)n.h[f]^=g[f]^g[f+8]}function i(n,e,r){r=0|r;for(var f=0,t=0;r>0;){var
@devi
devi / blake2s.js
Last active August 29, 2015 14:01
Blake2s implementation for javascript
(function(exports) {
'use strict';
// BLAKE2s implementation for javascript
// Written in 2014 by Devi Mandiri. Public domain.
/* jshint newcap: false */
/* jshint bitwise: false */
var iv = [
@devi
devi / Curve25519Donna.php
Last active August 29, 2015 14:01
curve25519-donna for PHP
<?php
/**
* PHP port of https://github.com/agl/curve25519-donna
*
* curve25519-donna is copyrighted by Google Inc.
*
*
* Usage:
* - Generate secret key:
* dd if=/dev/urandom bs=32 count=1 of="/path/to/keyfile"
<?php
class SimpleArray implements Iterator, ArrayAccess, Countable {
private $size = 1;
private $buffer = null;
private $index = 0;
@devi
devi / Curve25519.php
Created May 7, 2014 17:38
Curve25519 for PHP
<?php
class Curve25519 {
const CRYPTO_SCALARBYTES = 32;
protected $minusp = null;
public function __construct() {
$this->minusp = new SplFixedArray(32);
@devi
devi / elliptic.php
Last active August 29, 2015 14:00
PHP port of cryptocat elliptic.js
<?php
/**
* Port of cryptocat elliptic.js
*
* https://github.com/cryptocat/cryptocat/blob/master/src/core/js/lib/elliptic.js
* commit: b4c87fb6ff20afb069d7ba951afaf9db5fd9c242
*/
class curve25519 {
// p25519 is the curve25519 prime: 2^255 - 19
@devi
devi / genrsa.go
Created April 27, 2014 11:59
Generate RSA key pair in PEM format
// Generate RSA key pair in PEM format.
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"flag"
"fmt"
// httplistener is a simplified version of camlistore.org/pkg/webserver
package httplistener
import (
"crypto/rand"
"crypto/tls"
"fmt"
"github.com/bradfitz/runsit/listen"
"net"
"time"