An elliptic curve is made up of the following:
- A field, F_p.
- What this means is all arithmetic on scalars is modulo p.
- Modern ECC have p as some large prime.
- For curve25519, p = 2^255 - 19, a prime.
- An equation and it's parameters:
import Foundation | |
extension UnicodeScalar : ForwardIndexType { | |
public func successor() -> UnicodeScalar { | |
return UnicodeScalar(value + 1) | |
} | |
} | |
var operatorHeads: [UnicodeScalar] = Array("=-+!*%<>&|^~?".unicodeScalars) | |
operatorHeads += Array("\u{00A1}" ... "\u{00A7}") |
import random | |
class Montgomery: | |
# B*v^2 = u^3 + A*u^2 + u | |
def __init__(self, A, B, p): | |
self.A = A | |
self.B = B | |
self.p = p |
#!/usr/bin/python3 -O | |
from math import floor, log | |
def montgomery_ladder(x, n, op, select): | |
k = floor(log(n, 2)) + 1 | |
x1 = x | |
x2 = op(x, x) | |
for i in range(k - 2, -1, -1): | |
bit = 1 if n & (1 << i) else 0 |
""" | |
MIT License | |
Copyright (c) 2016 Michael Shihrer ([email protected]) | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
#import <CommonCrypto/CommonCrypto.h> |
import Darwin | |
@dynamicMemberLookup | |
struct Environment { | |
subscript(dynamicMember name: String) -> String? { | |
get { | |
guard let value = getenv(name) else { return nil } | |
return String(validatingUTF8: value) | |
} |
/// Returns a binary predicate using the given key path to create an ascending order | |
/// for elements of type `Root`. | |
func ascending<Root, Value: Comparable>(_ path: KeyPath<Root, Value>) -> (Root, Root) -> Bool { | |
return { $0[keyPath: path] < $1[keyPath: path] } | |
} | |
/// Returns a binary predicate using the given key path to create a descending order | |
/// for elements of type `Root`. | |
func descending<Root, Value: Comparable>(_ path: KeyPath<Root, Value>) -> (Root, Root) -> Bool { | |
return { $0[keyPath: path] > $1[keyPath: path] } |
/// A dictionary wrapper that uses a `CaseIterable` type as its key. | |
/// This differs from a dictionary in two ways: | |
/// | |
/// - Key-value pairs are accessed in a fixed order, which is the same | |
/// as the `Key`'s `allCases` property. | |
/// - Every possible key must have a value given, so using the key-based | |
/// subscript returns a non-optional value. | |
struct CaseMap<Key: CaseIterable & Hashable, Value> : Collection { | |
typealias Index = Key.AllCases.Index |