Back to index

texmacs  1.0.7.15
Functions
pdfencrypt.h File Reference
#include "pdfobj.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void pdf_enc_set_verbose (void)
pdf_objpdf_enc_id_array (void)
void pdf_enc_compute_id_string (char *dviname, char *pdfname)
void pdf_enc_set_label (unsigned long label)
void pdf_enc_set_generation (unsigned generation)
void pdf_enc_set_passwd (unsigned size, unsigned perm, char *dviname, char *pdfname)
void pdf_encrypt_data (unsigned char *data, unsigned long len)
pdf_objpdf_encrypt_obj (void)

Function Documentation

void pdf_enc_compute_id_string ( char *  dviname,
char *  pdfname 
)

Definition at line 83 of file pdfencrypt.c.

{
  char *date_string, *producer;
  time_t current_time;
  struct tm *bd_time;

  MD5_init(&md5_ctx);

  date_string = NEW (15, char);
  time(&current_time);
  bd_time = localtime(&current_time);
  sprintf (date_string, "%04d%02d%02d%02d%02d%02d",
          bd_time -> tm_year+1900, bd_time -> tm_mon+1, bd_time -> tm_mday,
          bd_time -> tm_hour, bd_time -> tm_min, bd_time -> tm_sec);
  MD5_write(&md5_ctx, (unsigned char *)date_string, strlen(date_string));
  RELEASE (date_string);

  producer = NEW (strlen(PRODUCER)+strlen(PACKAGE)+strlen(VERSION), char);
  sprintf(producer, PRODUCER, PACKAGE, VERSION);
  MD5_write(&md5_ctx, (unsigned char *)producer, strlen(producer));
  RELEASE (producer);

  MD5_write(&md5_ctx, (unsigned char *)dviname, strlen(dviname));
  MD5_write(&md5_ctx, (unsigned char *)pdfname, strlen(pdfname));
  MD5_final(id_string, &md5_ctx);
}

Here is the call graph for this function:

Definition at line 514 of file pdfencrypt.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_enc_set_generation ( unsigned  generation)

Definition at line 527 of file pdfencrypt.c.

{
  current_generation = generation;
}

Here is the caller graph for this function:

void pdf_enc_set_label ( unsigned long  label)

Definition at line 522 of file pdfencrypt.c.

{
  current_label = label;
}

Here is the caller graph for this function:

void pdf_enc_set_passwd ( unsigned  size,
unsigned  perm,
char *  dviname,
char *  pdfname 
)

Definition at line 368 of file pdfencrypt.c.

{
  register char *retry_passwd;

  while (1) {
    strcpy(owner_passwd, getpass("Owner password: "));
    retry_passwd = getpass("Re-enter owner password: ");
    if (!strcmp(owner_passwd, retry_passwd))
      break;
    fputs("Password is not identical.\nTry again.\n", stderr);
    fflush(stderr);
  }

  while (1) {
    strcpy(user_passwd, getpass("User password: "));
    retry_passwd = getpass("Re-enter user password: ");
    if (!strcmp(user_passwd, retry_passwd))
      break;
    fputs("Password is not identical.\nTry again.\n", stderr);
    fflush(stderr);
  }

  key_size = (unsigned char)(bits / 8);
  algorithm = (key_size == 5 ? 1 : 2);
  permission = (long) (perm | 0xC0U);
  revision = ((algorithm == 1 && permission < 0x100L) ? 2 : 3);
  if (revision == 3)
    permission |= ~0xFFFL;

  compute_owner_password();
  compute_user_password();
}

Here is the call graph for this function:

void pdf_enc_set_verbose ( void  )

Definition at line 77 of file pdfencrypt.c.

{
  if (verbose < 255) verbose++;
}
void pdf_encrypt_data ( unsigned char *  data,
unsigned long  len 
)

Definition at line 401 of file pdfencrypt.c.

{
  unsigned char *result;

  memcpy(in_buf, key_data, key_size);
  in_buf[key_size]   = (unsigned char)(current_label) & 0xFF;
  in_buf[key_size+1] = (unsigned char)(current_label >> 8) & 0xFF;
  in_buf[key_size+2] = (unsigned char)(current_label >> 16) & 0xFF;
  in_buf[key_size+3] = (unsigned char)(current_generation) & 0xFF;
  in_buf[key_size+4] = (unsigned char)(current_generation >> 8) & 0xFF;

  MD5_init(&md5_ctx);
  MD5_write(&md5_ctx, in_buf, key_size+5);
  MD5_final(md5_buf, &md5_ctx);
  
  result = NEW (len, unsigned char);
  ARC4_set_key(&key, (key_size > 10 ? MAX_KEY_LEN : key_size+5), md5_buf);
  ARC4(&key, len, data, result);
  memcpy(data, result, len);
  RELEASE (result);
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_encrypt_obj ( void  )

Definition at line 423 of file pdfencrypt.c.

{
  pdf_obj *doc_encrypt;

#ifdef DEBUG
  fprintf (stderr, "(pdf_encrypt_obj)");
#endif

  doc_encrypt = pdf_new_dict ();

  /* KEY  : Filter
   * TYPE : name
   * VALUE: (Required) The name of the security handler for this document;
   *        see below. Default value: Standard, for the built-in security
   *        handler.
   */
  pdf_add_dict (doc_encrypt, 
              pdf_new_name ("Filter"),
              pdf_new_name ("Standard"));
  /* KEY  : V
   * TYPE : number
   * VALUE: (Optional but strongly recommended) A code specifying the
   *        algorithm to be used in encrypting and decrypting the document:
   *        0  An algorithm that is undocumented and no longer supported,
   *           and whose use is strongly discouraged.
   *        1  Algorithm 3.1 on page 73, with an encryption key length
   *           of 40 bits; see below.
   *        2  (PDF 1.4) Algorithm 3.1 on page 73, but allowing encryption
   *           key lengths greater than 40 bits.
   *        3  (PDF 1.4) An unpublished algorithm allowing encryption key
   *           lengths ranging from 40 to 128 bits. (This algorithm is
   *           unpublished as an export requirement of the U.S. Department
   *           of Commerce.)
   *        The default value if this entry is omitted is 0, but a value
   *        of 1 or greater is strongly recommended.
   */
  pdf_add_dict (doc_encrypt, 
              pdf_new_name ("V"),
              pdf_new_number (algorithm));
  /* KEY  : Length
   * TYPE : integer
   * VALUE: (Optional; PDF 1.4; only if V is 2 or 3) The length of the
   *        encryption key, in bits. The value must be a multiple of 8,
   *        in the range 40 to 128. Default value: 40.
   */
  if (algorithm > 1)
    pdf_add_dict (doc_encrypt, 
                pdf_new_name ("Length"),
                pdf_new_number (key_size * 8));
  /* KEY  : R
   * TYPE : number
   * VALUE: (Required) A number specifying which revision of the standard
   *        security handler should be used to interpret this dictionary.
   *        The revison number should be 2 if the document is encrypted
   *        with a V value less than 2; otherwise this value should be 3.
   */
  pdf_add_dict (doc_encrypt, 
              pdf_new_name ("R"),
              pdf_new_number (revision));
  /* KEY  : O
   * TYPE : string
   * VALUE: (Required) A 32-byte string, based on both the owner and
   *        user passwords, that is used in computing the encryption
   *        key and in determining whether a valid owner password was
   *        entered.
   */
  pdf_add_dict (doc_encrypt, 
              pdf_new_name ("O"),
              pdf_new_string (opwd_string, 32));
  /* KEY  : U
   * TYPE : string
   * VALUE: (Required) A 32-byte string, based on the user password,
   *        that is used in determining whether to prompt the user
   *        for a password and, if so, whether a valid user or owner
   *        password was entered.
   */
  pdf_add_dict (doc_encrypt, 
              pdf_new_name ("U"),
              pdf_new_string (upwd_string, 32));
  /* KEY  : P
   * TYPE : (signed 32 bit) integer
   * VALUE: (Required) A set of flags specifying which operations are
   *        permitted when the document is opened with user access.
   */
  pdf_add_dict (doc_encrypt, 
              pdf_new_name ("P"),
              pdf_new_number (permission));

  return doc_encrypt;
}

Here is the call graph for this function:

Here is the caller graph for this function: