~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to sm/encrypt.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2009-03-08 22:46:47 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090308224647-gq17gatcl71lrc2k
Tags: 2.0.11-1
* New upstream release. (Closes: #496663)
* debian/control: Make the description a little more distinctive than
  gnupg v1's. Thanks Jari Aalto. (Closes: #496323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* encrypt.c - Encrypt a message
2
 
 *      Copyright (C) 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
 
2
 * Copyright (C) 2001, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of GnuPG.
5
5
 *
144
144
encode_session_key (DEK dek, gcry_sexp_t * r_data)
145
145
{
146
146
  gcry_sexp_t data;
147
 
  char * p, tmp[3];
148
 
  int i;
 
147
  char *p;
149
148
  int rc;
150
149
 
151
 
  p = xmalloc (64 + 2 * dek->keylen);
 
150
  p = xtrymalloc (64 + 2 * dek->keylen);
 
151
  if (!p)
 
152
    return gpg_error_from_syserror ();
152
153
  strcpy (p, "(data\n (flags pkcs1)\n (value #");
153
 
  for (i=0; i < dek->keylen; i++)
154
 
    {
155
 
      sprintf (tmp, "%02x", (unsigned char) dek->key[i]);
156
 
      strcat (p, tmp);   
157
 
    }
 
154
  bin2hex (dek->key, dek->keylen, p + strlen (p));
158
155
  strcat (p, "#))\n");
159
156
  rc = gcry_sexp_sscan (&data, NULL, p, strlen (p));
160
157
  xfree (p);
196
193
      return rc;
197
194
    }
198
195
 
199
 
  /* put the encoded cleartext into a simple list */
 
196
  /* Put the encoded cleartext into a simple list. */
 
197
  s_data = NULL; /* (avoid compiler warning) */
200
198
  rc = encode_session_key (dek, &s_data);
201
199
  if (rc)
202
 
  {
203
 
    log_error ("encode_session_key failed: %s\n", gpg_strerror (rc));
204
 
    return rc;
205
 
  }
 
200
    {
 
201
      log_error ("encode_session_key failed: %s\n", gpg_strerror (rc));
 
202
      return rc;
 
203
    }
206
204
 
207
205
  /* pass it to libgcrypt */
208
206
  rc = gcry_pk_encrypt (&s_ciph, s_data, s_pkey);