bitpay/copay — pull request #237 by matiu (2014-04-30 14:22:00+00:00)
Title: Feature/autheticated encrption aes/ccm mode 5

This implements CCM/AES mode for authenticated encryption.

SJSC support two modes CCM and OBC. OBC is faster, but have some
patents restrictions in certain countries, so I choose CCM. Default mode
can be changed in config.js.

CCM will encrypt and mac each package using the RECIPIENT sha256 of copayerID as a seed
for a Password-Based Key-Derivation Function (PBKDF2-HMAC-SHA256). This is the method specified by RSA's PKCS #5 standard. Iterations number is configurable in config.js, defaults to 1000. This should
ensure a good key even if there is any uneven distribution of ECDSA pubkeys in the 33 bytes space.
salt for PBKDF can be configured on config.js. Alternatively we could send a true random number for that key.

Since all peers know each other peer's pubkeys ONCE the wallet is complete, there is no need to keep
encrypting differently each message for each peer, that could be enhanced on the future.

More info on CCM/AES:
http://spark-university.s3.amazonaws.com/stanford-crypto/slides/07.4-authenc-annotated.pdf

On PBKDF2:
http://en.wikipedia.org/wiki/PBKDF2ll

Regarding using the Public key are a key for CCM:
http://security.stackexchange.com/questions/56964/is-it-safe-to-use-a-ecdsa-public-key-as-a-password-seed-for-gcm-aes/56966?noredirect=1#comment90428_56966
(note that this pubkeys (copayerIds) are kept secret and are not used to signing)

This is a rebase of: https://github.com/bitpay/copay/pull/224