Source Code Cross Referenced for WTauNafMultiplier.java in  » Security » Bouncy-Castle » org » bouncycastle » math » ec » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Security » Bouncy Castle » org.bouncycastle.math.ec 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.math.ec;
002:
003:        import java.math.BigInteger;
004:
005:        /**
006:         * Class implementing the WTNAF (Window
007:         * <code>&tau;</code>-adic Non-Adjacent Form) algorithm.
008:         */
009:        class WTauNafMultiplier implements  ECMultiplier {
010:            /**
011:             * Multiplies a {@link org.bouncycastle.math.ec.ECPoint.F2m ECPoint.F2m}
012:             * by <code>k</code> using the reduced <code>&tau;</code>-adic NAF (RTNAF)
013:             * method.
014:             * @param p The ECPoint.F2m to multiply.
015:             * @param k The integer by which to multiply <code>k</code>.
016:             * @return <code>p</code> multiplied by <code>k</code>.
017:             */
018:            public ECPoint multiply(ECPoint point, BigInteger k,
019:                    PreCompInfo preCompInfo) {
020:                if (!(point instanceof  ECPoint.F2m)) {
021:                    throw new IllegalArgumentException(
022:                            "Only ECPoint.F2m can be "
023:                                    + "used in WTauNafMultiplier");
024:                }
025:
026:                ECPoint.F2m p = (ECPoint.F2m) point;
027:
028:                ECCurve.F2m curve = (ECCurve.F2m) p.getCurve();
029:                int m = curve.getM();
030:                byte a = curve.getA().toBigInteger().byteValue();
031:                byte mu = curve.getMu();
032:                BigInteger[] s = curve.getSi();
033:
034:                ZTauElement rho = Tnaf.partModReduction(k, m, a, s, mu,
035:                        (byte) 10);
036:
037:                return multiplyWTnaf(p, rho, preCompInfo, a, mu);
038:            }
039:
040:            /**
041:             * Multiplies a {@link org.bouncycastle.math.ec.ECPoint.F2m ECPoint.F2m}
042:             * by an element <code>&lambda;</code> of <code><b>Z</b>[&tau;]</code> using
043:             * the <code>&tau;</code>-adic NAF (TNAF) method.
044:             * @param p The ECPoint.F2m to multiply.
045:             * @param lambda The element <code>&lambda;</code> of
046:             * <code><b>Z</b>[&tau;]</code> of which to compute the
047:             * <code>[&tau;]</code>-adic NAF.
048:             * @return <code>p</code> multiplied by <code>&lambda;</code>.
049:             */
050:            private ECPoint.F2m multiplyWTnaf(ECPoint.F2m p,
051:                    ZTauElement lambda, PreCompInfo preCompInfo, byte a, byte mu) {
052:                ZTauElement[] alpha;
053:                if (a == 0) {
054:                    alpha = Tnaf.alpha0;
055:                } else {
056:                    // a == 1
057:                    alpha = Tnaf.alpha1;
058:                }
059:
060:                BigInteger tw = Tnaf.getTw(mu, Tnaf.WIDTH);
061:
062:                byte[] u = Tnaf.tauAdicWNaf(mu, lambda, Tnaf.WIDTH, BigInteger
063:                        .valueOf(Tnaf.POW_2_WIDTH), tw, alpha);
064:
065:                return multiplyFromWTnaf(p, u, preCompInfo);
066:            }
067:
068:            /**
069:             * Multiplies a {@link org.bouncycastle.math.ec.ECPoint.F2m ECPoint.F2m}
070:             * by an element <code>&lambda;</code> of <code><b>Z</b>[&tau;]</code>
071:             * using the window <code>&tau;</code>-adic NAF (TNAF) method, given the
072:             * WTNAF of <code>&lambda;</code>.
073:             * @param p The ECPoint.F2m to multiply.
074:             * @param u The the WTNAF of <code>&lambda;</code>..
075:             * @return <code>&lambda; * p</code>
076:             */
077:            private static ECPoint.F2m multiplyFromWTnaf(ECPoint.F2m p,
078:                    byte[] u, PreCompInfo preCompInfo) {
079:                ECCurve.F2m curve = (ECCurve.F2m) p.getCurve();
080:                byte a = curve.getA().toBigInteger().byteValue();
081:
082:                ECPoint.F2m[] pu;
083:                if ((preCompInfo == null)
084:                        || !(preCompInfo instanceof  WTauNafPreCompInfo)) {
085:                    pu = Tnaf.getPreComp(p, a);
086:                    p.setPreCompInfo(new WTauNafPreCompInfo(pu));
087:                } else {
088:                    pu = ((WTauNafPreCompInfo) preCompInfo).getPreComp();
089:                }
090:
091:                // q = infinity
092:                ECPoint.F2m q = (ECPoint.F2m) p.getCurve().getInfinity();
093:                for (int i = u.length - 1; i >= 0; i--) {
094:                    q = Tnaf.tau(q);
095:                    if (u[i] != 0) {
096:                        if (u[i] > 0) {
097:                            q = q.addSimple(pu[u[i]]);
098:                        } else {
099:                            // u[i] < 0
100:                            q = q.subtractSimple(pu[-u[i]]);
101:                        }
102:                    }
103:                }
104:
105:                return q;
106:            }
107:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.