-- | Convert a user-supplied password into a scalar on a group.
passwordToScalar :: AbelianGroup group => group -> Password -> Scalar group
passwordToScalar group password =
  decodeScalar group oversized
  where
    oversized = expandPassword password (scalarSizeBytes group + 16) :: ByteString
    expandPassword (Password bytes) = expandData info bytes
    -- This needs to be exactly "SPAKE2 pw"
    -- See <https://github.com/bitwiseshiftleft/sjcl/pull/273/#issuecomment-185251593>
    info = "SPAKE2 pw"

-- | Turn an element into a message from this side of the protocol.
passwordToScalar :: AbelianGroup group => group -> Password -> Scalar group
passwordToScalar group password =
  decodeScalar group oversized
  where
    oversized = expandPassword password (scalarSizeBytes group + 16) :: ByteString
    expandPassword (Password bytes) = expandData info bytes
    -- This needs to be exactly "SPAKE2 pw"
    -- See <https://github.com/bitwiseshiftleft/sjcl/pull/273/#issuecomment-185251593>
    info = "SPAKE2 pw"

-- | Turn an element into a message from this side of the protocol.
passwordToScalar group password =
  decodeScalar group oversized
  where
    oversized = expandPassword password (scalarSizeBytes group + 16) :: ByteString
    expandPassword (Password bytes) = expandData info bytes
    -- This needs to be exactly "SPAKE2 pw"
    -- See <https://github.com/bitwiseshiftleft/sjcl/pull/273/#issuecomment-185251593>
    info = "SPAKE2 pw"

-- | Turn an element into a message from this side of the protocol.