Demonware/jose — pull request #3 by jaimeperez (2014-12-24 02:24:11+00:00)
Title: Fix several issues with JWE.

The issues are:
* the **AL** field is not correctly calculated. It must represent the **length in bits** of the *additional authenticated data*, not in bytes. Additionally, it must be represented as an unsigned 64-bit octet string in big-endian, not as a simple string.
* in order to compute the *authentication tag*, the **ciphertext** must be used, not the plaintext.
* in AES_CBC_HMAC_SHA2, the length of the input key equals to the digest size, that being 32, 48 and 64 octets for each of the three variants.
* the **integrity key** and **encryption key** are derived as the first and second half of the input key, respectively.

>The secondary keys MAC_KEY and ENC_KEY are generated from the input key K as follows. Each of these two keys is an octet string.
* MAC_KEY consists of the initial MAC_KEY_LEN octets of K, in order.
* ENC_KEY consists of the final ENC_KEY_LEN octets of K, in order.

>The number of octets in the input key K MUST be the sum of MAC_KEY_LEN and ENC_KEY_LEN. The values of these parameters are specified by the Authenticated Encryption algorithms in Sections 5.2.3 through 5.2.5. Note that the MAC key comes before the encryption key in the input key K; this is in the opposite order of the algorithm names in the identifier "AES_CBC_HMAC_SHA2".