~ubuntu-branches/ubuntu/hardy/gnupg/hardy-updates

« back to all changes in this revision

Viewing changes to g10/passphrase.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2006-12-12 15:56:56 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20061212155656-kk00wp4x0uq4tm1y
Tags: upstream-1.4.6
ImportĀ upstreamĀ versionĀ 1.4.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* passphrase.c -  Get a passphrase
2
 
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3
 
 *               2005 Free Software Foundation, Inc.
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
 
3
 *               2006 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
937
937
              goto agent_died;
938
938
            pw = xstrdup ("");
939
939
          }
940
 
        if( *pw && mode == 2 ) {
941
 
            char *pw2 = agent_get_passphrase ( keyid, 2, NULL, NULL, NULL,
942
 
                                               NULL, canceled );
943
 
            if (!pw2)
944
 
              {
945
 
                if (!opt.use_agent)
946
 
                  {
947
 
                    xfree (pw);
948
 
                    pw = NULL;
949
 
                    goto agent_died;
950
 
                  }
951
 
                pw2 = xstrdup ("");
952
 
              }
953
 
            if( strcmp(pw, pw2) ) {
 
940
        if( *pw && mode == 2 )
 
941
          {
 
942
            int i;
 
943
            for(i=0;i<opt.passwd_repeat;i++)
 
944
              {
 
945
                char *pw2 = agent_get_passphrase ( keyid, 2, NULL, NULL, NULL,
 
946
                                                   NULL, canceled );
 
947
                if (!pw2)
 
948
                  {
 
949
                    if (!opt.use_agent)
 
950
                      {
 
951
                        xfree (pw);
 
952
                        pw = NULL;
 
953
                        goto agent_died;
 
954
                      }
 
955
                    pw2 = xstrdup ("");
 
956
                  }
 
957
                if( strcmp(pw, pw2) )
 
958
                  {
 
959
                    xfree(pw2);
 
960
                    xfree(pw);
 
961
                    return NULL;
 
962
                  }
954
963
                xfree(pw2);
955
 
                xfree(pw);
956
 
                return NULL;
957
 
            }
958
 
            xfree(pw2);
959
 
        }
 
964
              }
 
965
          }
960
966
    }
961
967
    else if( fd_passwd ) {
962
968
        /* Return the passphrase we have store in FD_PASSWD. */
972
978
        /* Read the passphrase from the tty or the command-fd. */
973
979
        pw = cpr_get_hidden("passphrase.enter", _("Enter passphrase: ") );
974
980
        tty_kill_prompt();
975
 
        if( mode == 2 && !cpr_enabled() ) {
976
 
            char *pw2 = cpr_get_hidden("passphrase.repeat",
977
 
                                       _("Repeat passphrase: ") );
978
 
            tty_kill_prompt();
979
 
            if( strcmp(pw, pw2) ) {
 
981
        if( mode == 2 && !cpr_enabled() )
 
982
          {
 
983
            int i;
 
984
            for(i=0;i<opt.passwd_repeat;i++)
 
985
              {
 
986
                char *pw2 = cpr_get_hidden("passphrase.repeat",
 
987
                                           _("Repeat passphrase: ") );
 
988
                tty_kill_prompt();
 
989
                if( strcmp(pw, pw2) )
 
990
                  {
 
991
                    xfree(pw2);
 
992
                    xfree(pw);
 
993
                    return NULL;
 
994
                  }
980
995
                xfree(pw2);
981
 
                xfree(pw);
982
 
                return NULL;
983
 
            }
984
 
            xfree(pw2);
985
 
        }
 
996
              }
 
997
          }
986
998
    }
987
999
 
988
1000
    if( !pw || !*pw )
1036
1048
            if( create && !pass ) {
1037
1049
                randomize_buffer(s2k->salt, 8, 1);
1038
1050
                if( s2k->mode == 3 )
1039
 
                    s2k->count = 96; /* 65536 iterations */
 
1051
                    s2k->count = opt.s2k_count;
1040
1052
            }
1041
1053
 
1042
1054
            if( s2k->mode == 3 ) {
1043
 
                count = (16ul + (s2k->count & 15)) << ((s2k->count >> 4) + 6);
 
1055
                count = S2K_DECODE_COUNT(s2k->count);
1044
1056
                if( count < len2 )
1045
1057
                    count = len2;
1046
1058
            }