Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsStreamCipher Class Reference

#include <nsStreamCipher.h>

Inheritance diagram for nsStreamCipher:
Inheritance graph
[legend]
Collaboration diagram for nsStreamCipher:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsStreamCipher ()
void init (in nsIKeyObject aKey)
 Initialize a stream cipher.
void initWithIV (in nsIKeyObject aKey,[const, array, size_is(aIVLen)] in octet aIV, in unsigned long aIVLen)
 Initialize a stream cipher with an initialization vector.
void update ([const, array, size_is(aLen)] in octet aData, in unsigned long aLen)
 Update from an array of bytes.
void updateFromStream (in nsIInputStream aStream, in long aLen)
 Update from a stream.
void updateFromString (in ACString aInput)
 A more script friendly method (not in nsICryptoHash interface).
ACString finish (in PRBool aASCII)
void discard (in long aLen)
 Discard aLen bytes of the keystream.

Private Member Functions

 ~nsStreamCipher ()
nsresult InitWithIV_ (nsIKeyObject *aKey, SECItem *aIV)
 nsStreamCipher (nsStreamCipher &)

Private Attributes

PK11Context * mContext
nsCString mValue

Detailed Description

Definition at line 48 of file nsStreamCipher.h.


Constructor & Destructor Documentation

Definition at line 42 of file nsStreamCipher.cpp.

  : mContext(NULL)
{
}

Definition at line 47 of file nsStreamCipher.cpp.

{
  if (mContext)
    PK11_DestroyContext(mContext, PR_TRUE /* free sub-objects */);
}

Here is the call graph for this function:


Member Function Documentation

void nsIStreamCipher::discard ( in long  aLen) [inherited]

Discard aLen bytes of the keystream.

These days 1536 is considered a decent amount to drop to get the key state warmed-up enough for secure usage.

ACString nsIStreamCipher::finish ( in PRBool  aASCII) [inherited]
Parameters:
aASCIIif true then the returned value is a base-64 encoded string. if false, then the returned value is binary data.
void nsIStreamCipher::init ( in nsIKeyObject  aKey) [inherited]

Initialize a stream cipher.

Parameters:
aKeynsIKeyObject
void nsIStreamCipher::initWithIV ( in nsIKeyObject  aKey,
[const, array, size_is(aIVLen)] in octet  aIV,
in unsigned long  aIVLen 
) [inherited]

Initialize a stream cipher with an initialization vector.

Parameters:
aKeynsIKeyObject
aIVthe initialization vector
aIVLenthe length of the initialization vector
nsresult nsStreamCipher::InitWithIV_ ( nsIKeyObject aKey,
SECItem *  aIV 
) [private]

Definition at line 54 of file nsStreamCipher.cpp.

{
  NS_ENSURE_ARG_POINTER(aKey);

  // Make sure we have a SYM_KEY.
  PRInt16 keyType;
  nsresult rv = aKey->GetType(&keyType);
  NS_ENSURE_SUCCESS(rv, rv);
  if (keyType != nsIKeyObject::SYM_KEY)
    return NS_ERROR_INVALID_ARG;

  if (mContext)
    PK11_DestroyContext(mContext, PR_TRUE /* free sub-objects */);

  // Get the PK11SymKey out of the key object and create the PK11Context.
  void* keyObj;
  rv = aKey->GetKeyObj(&keyObj);
  NS_ENSURE_SUCCESS(rv, rv);

  PK11SymKey *symkey = NS_REINTERPRET_CAST(PK11SymKey*, keyObj);
  if (!symkey)
    return NS_ERROR_FAILURE;

  CK_MECHANISM_TYPE cipherMech = PK11_GetMechanism(symkey);

  SECItem *param = nsnull;
  // aIV may be null
  param = PK11_ParamFromIV(cipherMech, aIV);
  if (!param)
    return NS_ERROR_FAILURE;

  mContext = PK11_CreateContextBySymKey(cipherMech, CKA_ENCRYPT,
                                        symkey, param);

  SECITEM_FreeItem(param, PR_TRUE);

  // Something went wrong if mContext doesn't exist.
  if (!mContext)
    return NS_ERROR_FAILURE;

  // Everything went ok.      
  mValue.Truncate();
  return NS_OK;
}

Here is the call graph for this function:

void nsIStreamCipher::update ( [const, array, size_is(aLen)] in octet  aData,
in unsigned long  aLen 
) [inherited]

Update from an array of bytes.

void nsIStreamCipher::updateFromStream ( in nsIInputStream  aStream,
in long  aLen 
) [inherited]

Update from a stream.

void nsIStreamCipher::updateFromString ( in ACString  aInput) [inherited]

A more script friendly method (not in nsICryptoHash interface).


Member Data Documentation

PK11Context* nsStreamCipher::mContext [private]

Definition at line 67 of file nsStreamCipher.h.

Definition at line 70 of file nsStreamCipher.h.


The documentation for this class was generated from the following files: