~ubuntu-branches/ubuntu/dapper/phpmyadmin/dapper-updates

« back to all changes in this revision

Viewing changes to libraries/blowfish.php

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Roszatycki
  • Date: 2004-12-13 19:23:57 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20041213192357-5jfwhvbnxaip4zbv
Tags: 2:2.6.1-rc1-1
* New upstream release.
* Security fix: Command execution and file disclosure was found.
  See http://www.phpmyadmin.net/home_page/security.php?issue=PMASA-2004-4
  Closes: #285488.
* Remove 003.non_standard_port_fix.diff applied to upstream.
* Add commented out options 'extension' and 'AllowRoot' to default config
  file.
* Support mysqli.so extension. Autodetect modules from 'extension' option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
 
 
3
/* $Id: blowfish.php,v 2.3 2004/11/24 12:17:55 lem9 Exp $ */
 
4
// vim: expandtab sw=4 ts=4 sts=4:
 
5
 
3
6
/**
4
7
 * The Cipher_blowfish:: class implements the Cipher interface enryption data
5
8
 * using the Blowfish algorithm.
12
15
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
13
16
 *
14
17
 * @author  Mike Cochrane <mike@graftonhall.co.nz>
15
 
 * @version $Revision: 2.2 $
 
18
 * @version $Revision: 2.3 $
16
19
 * @since   Horde 2.2
17
20
 * @package horde.cipher
18
21
 */
468
471
    }
469
472
 
470
473
}
 
474
 
 
475
// higher-level functions:
 
476
 
 
477
/**
 
478
 * String padding
 
479
 *
 
480
 * @param   string  input string
 
481
 * @param   integer length of the result
 
482
 * @param   string  the filling string
 
483
 * @param   integer padding mode
 
484
 *
 
485
 * @return  string  the padded string
 
486
 *
 
487
 * @access  public
 
488
 */
 
489
function full_str_pad($input, $pad_length, $pad_string = '', $pad_type = 0) {
 
490
    $str = '';
 
491
    $length = $pad_length - strlen($input);
 
492
    if ($length > 0) { // str_repeat doesn't like negatives
 
493
        if ($pad_type == STR_PAD_RIGHT) { // STR_PAD_RIGHT == 1
 
494
            $str = $input.str_repeat($pad_string, $length);
 
495
        } elseif ($pad_type == STR_PAD_BOTH) { // STR_PAD_BOTH == 2
 
496
            $str = str_repeat($pad_string, floor($length/2));
 
497
            $str .= $input;
 
498
            $str .= str_repeat($pad_string, ceil($length/2));
 
499
        } else { // defaults to STR_PAD_LEFT == 0
 
500
            $str = str_repeat($pad_string, $length).$input;
 
501
        }
 
502
    } else { // if $length is negative or zero we don't need to do anything
 
503
        $str = $input;
 
504
    }
 
505
    return $str;
 
506
}
 
507
 
 
508
/**
 
509
 * Encryption using blowfish algorithm
 
510
 *
 
511
 * @param   string  original data
 
512
 * @param   string  the secret
 
513
 *
 
514
 * @return  string  the encrypted result
 
515
 *
 
516
 * @access  public
 
517
 *
 
518
 * @author  lem9
 
519
 */
 
520
function PMA_blowfish_encrypt($data, $secret) {
 
521
    $pma_cipher = new Horde_Cipher_blowfish;
 
522
    $encrypt = '';
 
523
    for ($i=0; $i<strlen($data); $i+=8) {
 
524
        $block = substr($data, $i, 8);
 
525
        if (strlen($block) < 8) {
 
526
            $block = full_str_pad($block,8,"\0", 1);
 
527
        }
 
528
        $encrypt .= $pma_cipher->encryptBlock($block, $secret);
 
529
    }
 
530
    return base64_encode($encrypt);
 
531
}
 
532
 
 
533
/**
 
534
 * Decryption using blowfish algorithm
 
535
 *
 
536
 * @param   string  encrypted data
 
537
 * @param   string  the secret
 
538
 *
 
539
 * @return  string  original data
 
540
 *
 
541
 * @access  public
 
542
 *
 
543
 * @author  lem9
 
544
 */
 
545
function PMA_blowfish_decrypt($encdata, $secret) {
 
546
    $pma_cipher = new Horde_Cipher_blowfish;
 
547
    $decrypt = '';
 
548
    $data = base64_decode($encdata);
 
549
    for ($i=0; $i<strlen($data); $i+=8) {
 
550
        $decrypt .= $pma_cipher->decryptBlock(substr($data, $i, 8), $secret);
 
551
    }
 
552
    return trim($decrypt);
 
553
}
 
554
 
471
555
?>